Skip to main content

Magical function composition

Project description

incant🪄: a little magic for your functions

PyPI Build Coverage Supported Python versions Black


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


Download files

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

Source Distribution

incant-23.2.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

incant-23.2.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

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

Hashes for incant-23.2.0.tar.gz
Algorithm Hash digest
SHA256 2b0d4599e338da976b625ec9a4dd2736a6b0216ef01bcc39ddc30214407861a1
MD5 55382407a0ace2ab905d4634c031d56d
BLAKE2b-256 552a218e683a27eea98916f3ecceec6983a524a4873869e6e078aa7e055caa86

See more details on using hashes here.

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

Hashes for incant-23.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67bba5e2d172c0f862edb3cc752d6e37ab4681b202e42914a15faadbd6da2aff
MD5 965c5cdd66ac5913e234b49a983699a6
BLAKE2b-256 72dcb9ae6aa98fccd114c6e9c3e5b9bccf660ce30137bbd2d47102fa929a1bb7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page