incant🪄: a little magic for your functions
incant is a Python open source library for composing and calling functions. Going by the old, humorous adage that dependency injection is simply passing arguments to functions, incant is a toolkit that is well suited to that use case.
incant will help you with:
- all kinds of dependency injection scenarios
- adapting interfaces of third-party libraries to make them more flexible
- generically wrapping functions and coroutines for instrumentation
- creating signature-altering decorators
- calling functions and coroutines with unknown signatures safely
- ... and much more!
For example:
from incant import Incanter
incanter = Incanter()
@incanter.register_by_name
def now() -> float:
"""
Return the current timestamp.
We can replace this for testing later.
"""
from time import time
return time()
def my_function(now: float) -> None:
print(f"The time now is {now}")
incanter.compose_and_call(my_function)
incant has a fully type-annotated interface for use with Mypy and Pyright. incant works by generating Python code at runtime, and is extremely efficient. (incant is the fastest Python dependency injection framework we're aware of.)
If you're familiar with pytest, incant dependency factories are roughly equivalent to pytest fixtures.
Project Information
License
incant is written by Tin Tvrtković and distributed under the terms of the Apache-2.0 license.
Release files for incant 25.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| incant-25.1.0.tar.gz | 538.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| incant-25.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 555.3 kB
Release files / incant-25.1.0.tar.gz
| Download URL | incant-25.1.0.tar.gz |
|---|---|
| Size | 538.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3624bcd81e96145921b008d4a0111779bb9fc8e15052ae6307cf6ec7343021c3
|
|
BLAKE2b-256 checksum How to use checksums |
4afd0b842adae881846e73770dba3ce55251cb98a893ccd9fb80b430d4256d5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2025.
Transparency logRelease files / incant-25.1.0-py3-none-any.whl
| Download URL | incant-25.1.0-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f32418e346351eaa525350ee0953f6d02d710cd83c54e872f7de7cd64fecb343
|
|
BLAKE2b-256 checksum How to use checksums |
aaf9bb5a0d05ffc5eea4546696e9b3113fbda3b64838fda52a162b5ec9451f7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2025.
Transparency log