You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

pynjector

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pynjector

A lightweight Dependency Injection (DI) container for Python

0.1.3
pipPyPI
Maintainers
1

Pynjector

PyPI

A lightweight Dependency Injection (DI) container for Python that allows automatic resolution of dependencies based on constructor type hints.

🚀 Features

  • Simple and intuitive API
  • Automatic dependency resolution based on type hints
  • Supports binding classes, factory functions, and pre-initialized instances
  • Inspired by C#'s dependency injection approach

📦 Installation

Install via pip:

pip install pynjector

Install via poetry:

poetry add pynjector

🎯 Usage

from src.pynjector import DIContainer


class Database:
    def query(self) -> str:
        return "Data from Database"


class Service:
    def __init__(self, db: Database):
        self.db = db

    def get_data(self) -> str:
        return self.db.query()


# Create the pynjector
container = DIContainer()

# Register dependencies
container.bind(Database)

# Resolve a service instance
service = container.resolve(Service)

print(service.get_data())  # Output: "Data from Database"

Keywords

dependency injection

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.