Welcome to incant🪄!#

incant is a Python open source library for composing and calling functions. Dependency injection is but one of many use-cases served well by incant; wrapping functions with context managers for observability is another.

incant includes support for:

  • a convenience layer with a simple API, based on a powerful and fast performance layer

  • a very flexible system for matching dependencies using inspect.Parameter, including the parameter name, type annotation and default value

  • sync and async functions and dependencies

  • sync and async context manager dependencies

  • no global state

  • attaching arbitrary external dependencies to functions (forced dependencies), commonly used for side-effects

incant has a very lean API surface, the core API being:

incant is able to leverage runtime type annotations but is also capable of functioning without them. incant is also fully type-annotated for use with Mypy and smart editors.

The Tutorial contains a walkthough and some real-life use cases of incant.

If you’re coming from a pytest background, incant dependency factories are roughly equivalent to pytest fixtures.


To install incant, simply:

$ pip install incant