Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyCDI

https://travis-ci.org/ettoreleandrotognoli/python-cdi.svg?branch=master https://codecov.io/gh/ettoreleandrotognoli/python-cdi/branch/master/graph/badge.svg https://badge.fury.io/py/pycdi.svg https://img.shields.io/pypi/dm/pycdi.svg Maintainability Test Coverage CodeFactor

A simple Python CDI ( Code Dependency Injection) Library.

See the code of conduct.

Install

Install stable pycdi

pip install pycdi

Install latest pycdi

pip install git+https://github.com/ettoreleandrotognoli/python-cdi

Usage

Python2 & Python3

You can see more examples in the examples folder (examples/common).

import logging
from logging import Logger

from pycdi import Inject, Singleton, Producer
from pycdi.shortcuts import call


@Producer(str, _context='app_name')
def get_app_name():
    return 'PyCDI'


@Singleton(produce_type=Logger)
@Inject(app_name=str, _context='app_name')
def get_logger(app_name):
    return logging.getLogger(app_name)


@Inject(name=(str, 'app_name'), logger=Logger)
def main(name, logger):
    logger.info('I\'m starting...')
    print('Hello World!!!\nI\'m a example of %s' % name)
    logger.debug('I\'m finishing...')


call(main)

Python 3

With Python 3 it is possible to define the types of injection with Python type hints.

You can see more examples in the examples folder( examples/py3/ ).

import logging
from logging import Logger

from pycdi import Inject, Singleton, Producer
from pycdi.shortcuts import call


@Producer(_context='app_name')
def get_app_name() -> str:
    return 'PyCDI'


@Singleton()
@Inject(logger_name='app_name')
def get_logger(logger_name: str) -> Logger:
    return logging.getLogger(logger_name)


@Inject(name='app_name')
def main(name: str, logger: Logger):
    logger.info('I\'m starting...')
    print('Hello World!!!\nI\'m an example of %s' % name)
    logger.debug('I\'m finishing...')


call(main)

Metadata

Release files for pycdi 0.1.dev1669730582

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycdi 0.1.dev1669730582
File Size Uploaded Provenance Actions
pycdi-0.1.dev1669730582.tar.gz 6.9 kB Without provenance Details for pycdi-0.1.dev1669730582.tar.gz

Release files / pycdi-0.1.dev1669730582.tar.gz

Download URL pycdi-0.1.dev1669730582.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e821e220e9a65069bd8fb4cf7ffa1fc3a9370df9eb8e42112445a5f641cf3c4c
BLAKE2b-256 checksum
How to use checksums
a4a6deac72a05596ff6646a5ea69851c347a832af9ebf6934af469552c49df78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Security for pycdi 0.1.dev1669730582

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page