Skip to main content

Dependency injection library

Project description

# FunDI

Solution for problem no one had before

Fun stays for function(or for fun if you wish) and DI for Dependency Injection

This library provides fast(to write!) and convenient(to use!) Dependency Injection for functional programming on python.

Why?

This library was inspired by FastAPI's dependency injection. The reasons for its existence are simple:

  • A standalone dependency injection library. DI shouldn't be tied to a specific framework.
  • It simplifies code writing. Dependency injection reduces boilerplate and improves maintainability.
  • Lack of DI libraries for functional programming in Python. Or maybe I just didn't want to find one :3

No more words, let's try!

from contextlib import ExitStack

from fundi import scan, from_, inject


def require_user():
    return "Alice"


def greet(user: str = from_(require_user)):
    print(f"Hello, {user}!")


with ExitStack() as stack:
    inject({}, scan(greet), stack)

See the documentation to get more examples: https://fundi.readthedocs.io/en/latest/

Component explanation:

  • fundi.from_ - Helps define dependencies.

    Use cases:

    • Tell resolver to resolve parameter value by its type, not name (ex: parameter: from_(Session))

    • Define dependency (ex: parameter: type = from_(dependency)).

      In this case it can be replaced with fundi.scan.scan (ex: parameter: type = scan(dependency))

  • fundi.scan - Scans function for dependencies. Returns CallableInfo object that is used by all functions that resolve dependencies.

  • fundi.order - returns order in which dependencies will be resolved

  • fundi.tree - returns dependency resolving tree

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

fundi-0.0.8.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fundi-0.0.8-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file fundi-0.0.8.tar.gz.

File metadata

  • Download URL: fundi-0.0.8.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for fundi-0.0.8.tar.gz
Algorithm Hash digest
SHA256 6bdc3d2ce2869072bd6b64ae6befb3e5b4bea3a08da378b32d6d237d7b681caf
MD5 f037b57e6765ddedf29baa2880a879f3
BLAKE2b-256 5046cb2cb4fa34e803d1368bf3ee5cf5dbb459cb1547d8f69b5f8ac808579b8e

See more details on using hashes here.

File details

Details for the file fundi-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: fundi-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.26

File hashes

Hashes for fundi-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 78d741f069615a6865decc0f668b5aac32903fbf12bb6574816c04b6c6d97a9a
MD5 7ff0c3298bb5357d4fc744529db21794
BLAKE2b-256 a4e8fd984f700327e5dc47a9f127d3747a60615c22021716a9d92c6cee20101e

See more details on using hashes here.

Supported by

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