Skip to main content

Python typed object schema validation

Project description

typedi

Build PyPI version Coverage Status

Simple typed dependency injection container.

To install from python package index simply type (no dependencies):

pip install typedi

Or, if you don't want to bring a dependency inside a project simply copy and paste typedi.py inside your project

Usage

Containers

typedi comes with a default shared container, to add or retrieve instances from it import it anywhere you need - usually in some initialization/bootstrapping logic.

from typedi import container

Or you could also create your own DI containers:

from typedi import Container

my_container = Container()

Instance bindings, "user-managed singletons"

from typedi import container

class MyClass:
    pass

instance = MyClass()
container.register_instance(instance)

# anywhere else
from typedi import container

instance = container.get_instance(MyClass)

Class bindings

from typedi import container

class MyClass:
    pass

container.register_class(MyClass)

# anywhere else
from typedi import container

auto_instantiated_instance = container.get_instance(MyClass)

Class bindings with inheritance

from typedi import container

class MyClass:
    pass

class ChildOfMyClass(MyClass):
    pass

container.register_class(ChildOfMyClass)

# anywhere else
from typedi import container

auto_instantiated_instance = container.get_instance(MyClass)  # type: ChildOfMyClass

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

typedi-0.2.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

typedi-0.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file typedi-0.2.0.tar.gz.

File metadata

  • Download URL: typedi-0.2.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for typedi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c2b4026955618d647abb00ad2327100899479a6e37032c9d4b492971ec2c5bd4
MD5 259ff425f72a22fe0948db7738a4b71a
BLAKE2b-256 06937f75edc108d290b81bd4c39d89b1a0dd0c01a9ecbd0389168c48b70f0e16

See more details on using hashes here.

File details

Details for the file typedi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: typedi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for typedi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd0014623b147ae4d97ab4e81571256b7897478546996b35e05b1d180ffc4467
MD5 76394f8bac7220f77f80db3ed2439343
BLAKE2b-256 5610a2d7775db59b2bde2a5d77d79511587d0b7e41f840a739b8b5dbdaa27cf3

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