Adapters
Adapters translate between a data source (SQLModel, SQLAlchemy, or custom) and HyperAdmin's view layer.
Built-in Adapters
| Adapter | Module | Works with |
|---|---|---|
SQLModelAdapter |
hyperadmin.adapters.sqlmodel |
SQLModel async models |
SQLAlchemyAdapter |
hyperadmin.adapters.sqlalchemy |
SQLAlchemy async models |
HyperAdmin auto-selects the right adapter at registration time via the adapter registry.
Writing a custom adapter
Subclass BaseAdapter and implement all abstract methods:
from hyperadmin.core.adapters import BaseAdapter
class MyAdapter(BaseAdapter):
async def get(self, pk):
...
async def list(self, page=1, page_size=10, search=None, filters=None, order_by=None):
# Return (items, total_count)
...
async def create(self, data):
...
async def update(self, pk, data):
...
async def delete(self, pk):
...
async def get_related(self, pk, field):
...
async def get_schema(self):
...
Register it with the adapter registry so HyperAdmin can discover it automatically:
from hyperadmin.adapters.registry import adapter_registry
adapter_registry.register(MyModel, MyAdapter)
API Reference
hyperadmin.core.adapters.BaseAdapter
Bases: ABC
Abstract base class for data adapters.
Defines the contract for all data operations (get, list, create, update, delete). Subclass this to add support for a new ORM or data source.
Example
class MyAdapter(BaseAdapter):
async def get(self, pk): ...
Source code in src/hyperadmin/core/adapters.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
create(data)
abstractmethod
async
Creates a new object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
A dictionary of data for the new object. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The created object. |
Source code in src/hyperadmin/core/adapters.py
153 154 155 156 157 158 159 160 161 162 163 164 | |
delete(pk)
abstractmethod
async
Deletes an object by its primary key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object to delete. |
required |
Source code in src/hyperadmin/core/adapters.py
180 181 182 183 184 185 186 187 188 | |
get(pk)
abstractmethod
async
Retrieves a single object by its primary key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The retrieved object, or None if not found. |
Source code in src/hyperadmin/core/adapters.py
115 116 117 118 119 120 121 122 123 124 125 126 | |
get_choices(field, q='', limit=50, offset=0, **filters)
abstractmethod
async
Return paginated, searchable choices for a relation field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
The relation field name on this adapter's model. |
required |
q
|
str
|
Optional search string (ILIKE match on string columns). |
''
|
limit
|
int
|
Max results to return. Must not exceed 200. |
50
|
offset
|
int
|
Number of rows to skip for pagination. |
0
|
**filters
|
Any
|
Extra equality filters forwarded to the query (cascading support). |
{}
|
Returns:
| Type | Description |
|---|---|
list[ChoiceItem]
|
A list of |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/hyperadmin/core/adapters.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
get_queryset(request=None)
Return additional equality filters merged into list() and get() queries.
The returned mapping has the shape {column_name: value} and is applied as
equality predicates before any view-layer filters. Use this hook to implement
features like row-level security or tenant scoping without leaking those concerns
into the view layer.
Subclasses may override this method directly, or callers may register a
per-request callable via :meth:set_queryset_filter. The callable is
re-evaluated on every list() / get() — no caching — so it must be pure
or request-scoped.
Default behaviour returns an empty dict, which is a no-op (backward compatible).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request | None
|
The active Starlette/FastAPI request, when available. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict of column-name to value pairs to be ANDed into the query's WHERE |
dict[str, Any]
|
clause. Returns |
Source code in src/hyperadmin/core/adapters.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
get_related(pk, field)
abstractmethod
async
Retrieves related objects for a given object and field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object. |
required |
field
|
str
|
The name of the relationship field. |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
A list of related objects. |
Source code in src/hyperadmin/core/adapters.py
190 191 192 193 194 195 196 197 198 199 200 201 202 | |
get_schema()
abstractmethod
async
Retrieves the schema definition for the model.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the model's schema. |
Source code in src/hyperadmin/core/adapters.py
204 205 206 207 208 209 210 211 212 | |
list(page=1, page_size=10, search=None, filters=None, order_by=None, search_fields=None)
abstractmethod
async
Retrieves a list of objects with optional pagination, searching, and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
The page number for pagination. |
1
|
page_size
|
int
|
The number of items per page. |
10
|
search
|
str | None
|
A search query to filter the results. |
None
|
filters
|
dict[str, Any] | None
|
A dictionary of filters to apply to the query. |
None
|
order_by
|
str | None
|
The field to order the results by. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[Any], int]
|
A tuple containing the list of objects and the total count of objects. |
Source code in src/hyperadmin/core/adapters.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
save_inline_rows(spec, rows, parent_pk)
abstractmethod
async
Persist validated inline rows — create, update, or delete as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
InlineModelSpec
|
The |
required |
rows
|
list[dict[str, Any]]
|
Validated row dicts, each optionally containing |
required |
parent_pk
|
Any
|
The primary key of the parent object to associate new rows with. |
required |
Source code in src/hyperadmin/core/adapters.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
set_queryset_filter(filter_fn)
Register a per-request callable that returns additional queryset filters.
The callable receives the current :class:starlette.requests.Request (or
None) and must return a dict of {column_name: value} equality filters.
It is re-invoked on every list() / get() so it may consult
request-scoped state (e.g. request.state.user).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_fn
|
QuerysetFilter
|
A callable taking an optional :class: |
required |
Source code in src/hyperadmin/core/adapters.py
87 88 89 90 91 92 93 94 95 96 97 98 99 | |
update(pk, data)
abstractmethod
async
Updates an existing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object to update. |
required |
data
|
dict[str, Any]
|
A dictionary of data to update the object with. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The updated object. |
Source code in src/hyperadmin/core/adapters.py
166 167 168 169 170 171 172 173 174 175 176 177 178 | |
hyperadmin.adapters.sqlmodel.SQLModelAdapter
Bases: BaseAdapter
Data adapter for SQLModel.
Source code in src/hyperadmin/adapters/sqlmodel.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
create(data)
async
Creates a new object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
A dictionary of data for the new object. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The created object. |
Source code in src/hyperadmin/adapters/sqlmodel.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
delete(pk)
async
Deletes an object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object to delete. |
required |
Source code in src/hyperadmin/adapters/sqlmodel.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
get(pk)
async
Retrieves a single object by its primary key.
Any filters returned by :meth:get_queryset are merged into the WHERE clause
before the primary-key predicate so excluded rows resolve to None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The retrieved object, or None if not found. |
Source code in src/hyperadmin/adapters/sqlmodel.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
get_choices(field, q='', limit=50, offset=0, **filters)
async
Return paginated, searchable choices for a relation field.
Performs a single SELECT on the related model — no N+1.
Source code in src/hyperadmin/adapters/sqlmodel.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
get_related(pk, field)
async
Retrieves related objects for a given object and field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object. |
required |
field
|
str
|
The name of the related field. |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
A list of related objects. |
Source code in src/hyperadmin/adapters/sqlmodel.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
get_schema()
async
Returns the JSON schema for the model.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the JSON schema. |
Source code in src/hyperadmin/adapters/sqlmodel.py
198 199 200 201 202 203 204 205 | |
list(page=1, page_size=10, search=None, filters=None, order_by=None, search_fields=None)
async
Retrieves a list of objects with optional pagination, searching, and filtering.
Filters returned by :meth:get_queryset are applied before any
view-layer filters so they cannot be bypassed. The same predicates are
included in the count query, keeping pagination math consistent.
Source code in src/hyperadmin/adapters/sqlmodel.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
save_inline_rows(spec, rows, parent_pk)
async
Persist validated inline rows — create, update, or delete as needed.
A fresh SQLModelAdapter is constructed for the inline model using
this adapter's engine so all operations share the same database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
InlineModelSpec
|
The |
required |
rows
|
list[dict[str, Any]]
|
Validated row dicts, each optionally containing |
required |
parent_pk
|
Any
|
The primary key of the parent object to associate new rows with. |
required |
Source code in src/hyperadmin/adapters/sqlmodel.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
update(pk, data)
async
Updates an existing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
The primary key of the object to update. |
required |
data
|
dict[str, Any]
|
A dictionary of data to update the object with. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The updated object. |
Source code in src/hyperadmin/adapters/sqlmodel.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
hyperadmin.adapters.sqlalchemy.SQLAlchemyAdapter
Bases: BaseAdapter
Source code in src/hyperadmin/adapters/sqlalchemy.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
get(pk)
async
Retrieve an object by primary key, applying any get_queryset filters.
Filters returned by :meth:get_queryset are ANDed with the primary-key
predicate so excluded rows resolve to None (not raised).
Source code in src/hyperadmin/adapters/sqlalchemy.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
get_choices(field, q='', limit=50, offset=0, **filters)
async
Return paginated, searchable choices for a relation field.
Performs a single SELECT on the related model — no N+1.
Source code in src/hyperadmin/adapters/sqlalchemy.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
save_inline_rows(spec, rows, parent_pk)
async
Persist validated inline rows — create, update, or delete as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
InlineModelSpec
|
The |
required |
rows
|
list[dict[str, Any]]
|
Validated row dicts, each optionally containing |
required |
parent_pk
|
Any
|
The primary key of the parent object to associate new rows with. |
required |
Source code in src/hyperadmin/adapters/sqlalchemy.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |