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-25.1.0.tar.gz (538.1 kB view details)

Uploaded Source

Built Distribution

incant-25.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file incant-25.1.0.tar.gz.

File metadata

  • Download URL: incant-25.1.0.tar.gz
  • Upload date:
  • Size: 538.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for incant-25.1.0.tar.gz
Algorithm Hash digest
SHA256 3624bcd81e96145921b008d4a0111779bb9fc8e15052ae6307cf6ec7343021c3
MD5 ca50cd2b67575687f0718b8bf141a2fe
BLAKE2b-256 4afd0b842adae881846e73770dba3ce55251cb98a893ccd9fb80b430d4256d5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for incant-25.1.0.tar.gz:

Publisher: pypi-package.yml on Tinche/incant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file incant-25.1.0-py3-none-any.whl.

File metadata

  • Download URL: incant-25.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for incant-25.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f32418e346351eaa525350ee0953f6d02d710cd83c54e872f7de7cd64fecb343
MD5 eef8bc7d2fc2c886dbf5c24ba6c7aca8
BLAKE2b-256 aaf9bb5a0d05ffc5eea4546696e9b3113fbda3b64838fda52a162b5ec9451f7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for incant-25.1.0-py3-none-any.whl:

Publisher: pypi-package.yml on Tinche/incant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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