API/Dashboard¶
- class chancy.plugins.api.Api(*, port: int = 8000, host: str = '127.0.0.1', debug: bool = False, allow_origins: list[str] | None = None, secret_key: str | None = None, authentication_backend: AuthBackend)[source]¶
Bases:
Plugin
Provides an API and a dashboard for viewing the state of the Chancy cluster.
Running this plugin requires a few additional dependencies, you can install them with:
pip install chancy[web]
To have the API run permanently on each Worker, you can add it to the plugins list when creating the Chancy instance:
from chancy.plugins.api import Api from chancy.plugins.api.auth import SimpleAuthBackend async with Chancy(..., plugins=[ Api( authentication_backend=SimpleAuthBackend({"admin": "password"}), secret_key="<a strong, random secret key>", ), ]) as chancy: ...
Note
The API is still mostly undocumented, as its development is driven by the needs of the dashboard and may change significantly before it becomes stable.
Since it’s very common to only want the dashboard temporarily, you can start it with the CLI. This can also be used to connect to a remote Chancy instance:
pip install chancy[cli,web] chancy --app worker.chancy worker web
This will run the API and dashboard on port 8000 by default (you can change this with the
--port
and--host
flags), and generate a temporary random password for the admin user.Screenshots¶
- param port:
The port to listen on.
- param host:
The host to listen on.
- param debug:
Whether to run the server in debug mode.
- param allow_origins:
A list of origins that are allowed to access the API.
- class chancy.plugins.api.SimpleAuthBackend(users: dict[str, str])[source]¶
Bases:
AuthBackend
A simple authentication backend that uses a dictionary of users and passwords.
- Parameters:
users – A dictionary of users and their passwords.
- class chancy.plugins.api.plugin.ApiPlugin(api)[source]¶
Bases:
ABC
A plugin that provides additional API endpoints.
- class chancy.plugins.api.core.CoreApiPlugin(api)[source]¶
Bases:
ApiPlugin
Core API plugin which implements the endpoints for jobs, queues, workers, etc…
- async static get_configuration(request, *, chancy, worker)[source]¶
Get the configuration of the Chancy instance.