Skip to main content

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 @inject on Cyclopts commands; annotate parameters with FromDishka[...].
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dishka_cyclopts-1.0.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

dishka_cyclopts-1.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

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

Hashes for dishka_cyclopts-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9777e61833a45d9e299bdc73a72225ea3dbdeb4c1b6c4c1c37b0d5315b4a5eb2
MD5 eab7231efb3c185d01458f6a692a032d
BLAKE2b-256 785bbb3e32cb107c0825e49f29390e754edd82a636cc6c27e3b46cfbdd7b9df9

See more details on using hashes here.

File details

Details for the file dishka_cyclopts-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dishka_cyclopts-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 733177eed82a84da7162bf78e2bffdbbb6f0b9909ba42bd67bdc89f55895fa8b
MD5 63a431f72b83002683275ebc517d7d8f
BLAKE2b-256 12d03c1a4b74a8f3b81839ea9f6b4705baef27ccd59147936cc18637306084be

See more details on using hashes here.

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