Magical function composition
Project description
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.
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
File details
Details for the file incant-23.2.0.tar.gz
.
File metadata
- Download URL: incant-23.2.0.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.9.3 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b0d4599e338da976b625ec9a4dd2736a6b0216ef01bcc39ddc30214407861a1 |
|
MD5 | 55382407a0ace2ab905d4634c031d56d |
|
BLAKE2b-256 | 552a218e683a27eea98916f3ecceec6983a524a4873869e6e078aa7e055caa86 |
File details
Details for the file incant-23.2.0-py3-none-any.whl
.
File metadata
- Download URL: incant-23.2.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.9.3 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67bba5e2d172c0f862edb3cc752d6e37ab4681b202e42914a15faadbd6da2aff |
|
MD5 | 965c5cdd66ac5913e234b49a983699a6 |
|
BLAKE2b-256 | 72dcb9ae6aa98fccd114c6e9c3e5b9bccf660ce30137bbd2d47102fa929a1bb7 |