Dishka integration for cyclopts
Project description
Dishka × Cyclopts
Async Dishka integration for Cyclopts. It injects dependencies into async CLI commands using the familiar @inject decorator.
Features
- Automatic scope management: async containers are closed after each command, so async generators/iterators are finalized.
- Drop-in decorator: use
@injecton Cyclopts commands; annotate parameters withFromDishka[...]. - Positional-friendly: injected params can precede user arguments; binding is normalized to kwargs.
Installation
Install using pip
pip install dishka-cyclopts
Or with uv
uv add dishka-cyclopts
Usage
from cyclopts import App
from dishka import FromDishka, Provider, Scope, make_async_container, provide
from dishka_cyclopts import inject, setup_dishka
class Dependencies(Provider):
@provide(scope=Scope.APP)
def meaning(self) -> int:
return 42
app = App(result_action="return_value")
setup_dishka(make_async_container(Dependencies()), app)
@app.command
@inject
async def main(value: FromDishka[int]) -> int:
return value
if __name__ == "__main__":
print(app())
setup_dishka patches Cyclopts to track the current app and stores the provided AsyncContainer inside app.state. After each command completes the container is closed, finalizing APP/REQUEST scoped resources (including async generators).
Requirements
- Python 3.10+
- Cyclopts >= 4.3.0
- Dishka >= 1.7.2
More Examples
Check out the examples directory for more detailed examples.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dishka_cyclopts-1.0.1.tar.gz.
File metadata
- Download URL: dishka_cyclopts-1.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9777e61833a45d9e299bdc73a72225ea3dbdeb4c1b6c4c1c37b0d5315b4a5eb2
|
|
| MD5 |
eab7231efb3c185d01458f6a692a032d
|
|
| BLAKE2b-256 |
785bbb3e32cb107c0825e49f29390e754edd82a636cc6c27e3b46cfbdd7b9df9
|
File details
Details for the file dishka_cyclopts-1.0.1-py3-none-any.whl.
File metadata
- Download URL: dishka_cyclopts-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
733177eed82a84da7162bf78e2bffdbbb6f0b9909ba42bd67bdc89f55895fa8b
|
|
| MD5 |
63a431f72b83002683275ebc517d7d8f
|
|
| BLAKE2b-256 |
12d03c1a4b74a8f3b81839ea9f6b4705baef27ccd59147936cc18637306084be
|