pypi_packages: datasette-configure-asgi
This data as json
name | summary | classifiers | description | author | author_email | description_content_type | home_page | keywords | license | maintainer | maintainer_email | package_url | platform | project_url | project_urls | release_url | requires_dist | requires_python | version | yanked | yanked_reason |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
datasette-configure-asgi | Datasette plugin for configuring arbitrary ASGI middleware | [] | # datasette-configure-asgi [](https://pypi.org/project/datasette-configure-asgi/) [](https://circleci.com/gh/simonw/datasette-configure-asgi) [](https://github.com/simonw/datasette-configure-asgi/blob/master/LICENSE) Datasette plugin for configuring arbitrary ASGI middleware ## Installation pip install datasette-configure-asgi ## Usage This plugin only takes effect if your `metadata.json` file contains relevant top-level plugin configuration in a `"datasette-configure-asgi"` configuration key. For example, to wrap your Datasette instance in the `asgi-log-to-sqlite` middleware configured to write logs to `/tmp/log.db` you would use the following: ```json { "plugins": { "datasette-configure-asgi": [ { "class": "asgi_log_to_sqlite.AsgiLogToSqlite", "args": { "file": "/tmp/log.db" } } ] } } ``` The `"datasette-configure-asgi"` key should be a list of JSON objects. Each object should have a `"class"` key indicating the class to be used, and an optional `"args"` key providing any necessary arguments to be passed to that class constructor. ## Plugin structure This plugin can be used to wrap your Datasette instance in any ASGI middleware that conforms to the following structure: ```python class SomeAsgiMiddleware: def __init__(self, app, arg1, arg2): self.app = app self.arg1 = arg1 self.arg2 = arg2 async def __call__(self, scope, receive, send): start = time.time() await self.app(scope, receive, send) end = time.time() print("Time taken: {}".format(end - start)) ``` So the middleware is a class with a constructor which takes the wrapped application as a first argument, `app`, followed by further named arguments to configure the middleware. It provides an `async def __call__(self, scope, receive, send)` method to implement the middleware's behavior. | Simon Willison | text/markdown | https://github.com/simonw/datasette-configure-asgi | Apache License, Version 2.0 | https://pypi.org/project/datasette-configure-asgi/ | https://pypi.org/project/datasette-configure-asgi/ | {"Homepage": "https://github.com/simonw/datasette-configure-asgi"} | https://pypi.org/project/datasette-configure-asgi/0.1/ | ["pytest ; extra == 'test'", "pytest-asyncio ; extra == 'test'", "asgiref (==3.1.2) ; extra == 'test'", "datasette ; extra == 'test'"] | 0.1 | 0 |