Skip to main content

A smart and lightweight dependency injector

Project description

Smarti - Smart Dependency Injection for Python

Just add the @autowired decorator to the class you want to autoload. To customize the loaded arguments (e.g., input specific enum value, with the argument name number) add it to the decorator like so @autowire(number=Enum.one).

Furthermore, you can override/pass down arguments recursively using name_kwargs. This will use the given parameters to initialize name.

All of the described ways to modify the used arguments are also applicable when initializing the class. This means that you could call an autoloaded class using A(a=4, b_kwargs={'x' = 3}) to modify local usage. These override the corresponding defaults of the decorator of class A.

When using singletons, different parameters will yield different instances, but the same will yield the same.

Everything is thread-safe when the ClassLoaderFlags.ALL_DEPENDENCIES_AUTOWIRED is specified. Additionally, this forces you to decorate the whole dependency tree. When using this flag, non-autowired classes raise a RuntimeError. To avoid such errors, use ClassLoaderFlags.IGNORE_POSSIBLE_THREAD_ERRORS, but it is not recommended.

Installs via pip:

pip install smarti

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

smarti-1.2.14.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

smarti-1.2.14-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file smarti-1.2.14.tar.gz.

File metadata

  • Download URL: smarti-1.2.14.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for smarti-1.2.14.tar.gz
Algorithm Hash digest
SHA256 58438921a77608fbd3f164db1c61b686769d8737823a48a84abd299167768b38
MD5 015ba14fd687d24751fb1494d673d69d
BLAKE2b-256 9ec96692af96ff8e0a4453feb25edebfc1244a84722fa6aef04c53f5d13bbaee

See more details on using hashes here.

File details

Details for the file smarti-1.2.14-py3-none-any.whl.

File metadata

  • Download URL: smarti-1.2.14-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for smarti-1.2.14-py3-none-any.whl
Algorithm Hash digest
SHA256 7e6857e2b1ff82d5eb693f4870d771ee6db1d352fa7097dcf39f5fe6f7bb57b3
MD5 ae5986888f4d712e77f42350b4b69be7
BLAKE2b-256 ea74d4d0b30c40215c916d20e3a20d78ae47dbf88ccb7fd00f3c588457574a41

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