Skip to main content

WIP router for Datasette plugins

Project description

datasette-plugin-router

PyPI Changelog Tests License

WIP router for Datasette plugins

Datasette plugins that have a lot of custom API endpoints can get tiresome to write by hand. datasette-plugin-router aims to be a small Python library that adds a FastAPI-like API for defining custom Datasette plugin endpoints.

  • Define routes with familiar GET/POST decorators
  • Define Pydantic-backed input/output schemas on JSON endpoints
  • register_routes() compatability
  • export to OpenAPI schema for codegen'ing clients

Sample usage:

from datasette import Response, hookimpl
from datasette_plugin_router import Router, Body
from pydantic import BaseModel

router = Router()

class Input(BaseModel):
    id: int
    name: str

class Output(BaseModel):
    id_negative: int
    name_upper: str

@router.POST(r"/-/demo1$", output=Output)
async def demo1(params: Body[Input]) -> Output:
    output = Output(
        id_negative=-1 * params.id,
        name_upper=params.name.upper(),
    )
    return Response.json(output.model_dump())


@router.GET(r"/-/hello/(?P<name>.*)$")
async def hello(name: str):
    return Response.html(f"<h1>Hello, {name}!</h1>")


@hookimpl
def register_routes():
    return router.routes()

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

datasette_plugin_router-0.0.1a2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

datasette_plugin_router-0.0.1a2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file datasette_plugin_router-0.0.1a2.tar.gz.

File metadata

File hashes

Hashes for datasette_plugin_router-0.0.1a2.tar.gz
Algorithm Hash digest
SHA256 a3c85209c22bbdf91f747decd5886a5cfff65b928a4b77270cc2724e21d14a2e
MD5 eec60af12175bb2ff56960242d703ac8
BLAKE2b-256 6cbbbe85dd7b4e17b697b50bf7fc7b27e2c8c2d4b7da87de898db5aac1b22b1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasette_plugin_router-0.0.1a2.tar.gz:

Publisher: publish.yml on datasette/datasette-plugin-router

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

File details

Details for the file datasette_plugin_router-0.0.1a2-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_plugin_router-0.0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 5be37425d992b1f3591caddb48454825d0036edcc1073b7cb1da484acf5dba4b
MD5 9584f6356450dfeeaa29cb2130dee865
BLAKE2b-256 0f003dba540ef88844732e2f4dc324f79119cb57aef7e85b76e1fdaa2fcccf99

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasette_plugin_router-0.0.1a2-py3-none-any.whl:

Publisher: publish.yml on datasette/datasette-plugin-router

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