Skip to main content

Auto-generated admin UI for HawkAPI + SQLAlchemy — list, detail, create, edit, delete with no boilerplate

Project description

hawkapi-admin

Auto-generated admin UI for HawkAPI + hawkapi-sqlalchemy models. Drop your model classes in and get list / detail / create / edit / delete views mounted under /admin — no boilerplate, no React, no JSON-schema duplication.

Install

pip install hawkapi-admin

Quickstart

from hawkapi import HawkAPI
from hawkapi_sqlalchemy import Base, TimestampMixin, init_database
from sqlalchemy.orm import Mapped, mapped_column

from hawkapi_admin import Admin, ModelResource, init_admin


class User(Base, TimestampMixin):
    __tablename__ = "users"
    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    email: Mapped[str] = mapped_column(unique=True)
    name: Mapped[str] = mapped_column(default="")


app = HawkAPI()
init_database(app, url="postgresql+asyncpg://…/myapp")

admin = init_admin(app, title="My App")
admin.register(User)                            # simplest form

Visit /admin — you get the index page, /admin/user (list), /admin/user/new (create form), /admin/user/{id} (detail), /admin/user/{id}/edit, and POST /admin/user/{id}/delete. All with sane widgets picked from each column's SQLAlchemy type.

Customizing a resource

from hawkapi_admin import ModelResource

admin.register(ModelResource(
    model=User,
    label="Account",
    label_plural="Accounts",
    icon="👤",
    list_display=("id", "email", "created_at"),
    list_search=("email", "name"),
    form_fields=("email", "name"),
    readonly_fields=("created_at",),
    page_size=25,
    can_delete=False,
))
Option Default Effect
name lowercased class name URL slug (/admin/<name>)
label class name Heading on detail / form
label_plural label + "s" Nav label & list-page heading
icon "" Prepended to nav label
list_display every column Columns shown on the list page
list_search () Columns searched by ?q=... (LIKE)
form_fields every non-PK column Columns shown in the form
readonly_fields () Columns rendered but not editable
page_size 50 Rows per list page
can_create / can_update / can_delete True Toggles the corresponding routes off

Widgets

hawkapi-admin picks an input widget per column type, automatically:

  • bool → checkbox
  • int / float<input type="number">
  • date / datetime → matching native input
  • String(length > 500) → textarea
  • Enum<select> with the declared choices
  • everything else → <input type="text">

Authentication

The plugin doesn't ship its own auth — it picks up whatever middleware you already attached. Combine with hawkapi-auth and gate the admin prefix:

from hawkapi_auth import requires_scopes


admin = Admin(title="Admin", url_prefix="/admin")
admin.register(User)
admin.attach(app)


@app.middleware("http")
async def gate_admin(request, call_next):
    if request.url.path.startswith("/admin"):
        # raises 401/403 if the JWT is missing / lacks the scope
        await requires_scopes("admin:read")(request)
    return await call_next(request)

Theming

The bundled CSS is roughly 60 lines, prefers system colors (light + dark mode), and lives inline in _base.html — copy that template into your own templates/ directory if you want to restyle. Jinja extends "_base.html" keeps working as long as the same blocks (title, content) are defined.

Development

git clone https://github.com/ashimov/hawkapi-admin.git
cd hawkapi-admin
uv sync --extra dev
uv run pytest -q
uv run ruff check . && uv run ruff format --check .
uv run pyright src/

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hawkapi_admin-0.2.0.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hawkapi_admin-0.2.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file hawkapi_admin-0.2.0.tar.gz.

File metadata

  • Download URL: hawkapi_admin-0.2.0.tar.gz
  • Upload date:
  • Size: 42.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hawkapi_admin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4810d2c7f66a41318395a74dad93b733bc97b2f5e5b4986c476f5e0db8f3eb9f
MD5 f57dd45a7e9577032f4250ab1b82d84c
BLAKE2b-256 22a64fb9c0f03b581448abe930f91349f64292891ccf10af701f42654a9f55bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for hawkapi_admin-0.2.0.tar.gz:

Publisher: release.yml on ashimov/hawkapi-admin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hawkapi_admin-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: hawkapi_admin-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hawkapi_admin-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa2363b3ba7737765fd559924048182513777647d7a48031da17393ae96b5ebb
MD5 4ac751314fb6e8327da657375477c6d8
BLAKE2b-256 969bc50535fcbf6b91f5ec889614ecd83d32d5fadfa7017fcb02fcf832c2b9d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for hawkapi_admin-0.2.0-py3-none-any.whl:

Publisher: release.yml on ashimov/hawkapi-admin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page