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.0.tar.gz (3.4 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.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file dishka_cyclopts-1.0.0.tar.gz.

File metadata

  • Download URL: dishka_cyclopts-1.0.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for dishka_cyclopts-1.0.0.tar.gz
Algorithm Hash digest
SHA256 471bda33bebf2e3b32d57714b4b9104edd27313dbdaf81e4fb90a0ec609956bc
MD5 ab38408a0b9a0bff924504bf38e95afb
BLAKE2b-256 2852ea1f46e43e74bfdb81d9afc4cda011aad1d9f3201c4bdbc80a66f8995cd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dishka_cyclopts-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 979f017101821f2bd8fb7e2d21b8e45532ea38574786aac725db87fe3ec8e9aa
MD5 e04dfb0a6487d370d0c4fde04fac41ac
BLAKE2b-256 754b2d6fc468f8b6ab0435b374fa928cd695ca6c2f7bab339fba042e47d06b03

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