跳转到主要内容

Datasette插件,用于配置任意ASGI中间件

项目描述

datasette-configure-asgi

PyPI CircleCI License

Datasette插件,用于配置任意ASGI中间件

安装

pip install datasette-configure-asgi

用法

此插件仅在您的metadata.json文件中包含相关顶级插件配置时才有效,配置键为"datasette-configure-asgi"

例如,要将您的Datasette实例包装在配置为将日志写入/tmp/log.dbasgi-log-to-sqlite中间件中,您将使用以下内容

{
    "plugins": {
        "datasette-configure-asgi": [
            {
                "class": "asgi_log_to_sqlite.AsgiLogToSqlite",
                "args": {
                    "file": "/tmp/log.db"
                }
            }
        ]
    }
}

"datasette-configure-asgi"键应是一个JSON对象列表。每个对象应有一个"class"键,指示要使用的类,以及一个可选的"args"键,提供传递给该类构造函数的任何必要参数。

插件结构

此插件可用于将您的Datasette实例包装在任何符合以下结构的ASGI中间件中

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))

因此,中间件是一个具有构造函数的类,该构造函数将包装的应用程序作为第一个参数app,然后是进一步命名的参数以配置中间件。它提供一个async def __call__(self, scope, receive, send)方法来实现中间件的行为。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

此发布版本没有可用的源分布文件。有关生成分布存档的教程。

构建分布

datasette_configure_asgi-0.1-py3-none-any.whl (7.0 kB 查看哈希值)

上传于 Python 3

由以下机构支持