
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Fusebox is a lightweight and Pythonic dependency injection (DI) container built for simplicity and minimalism. It allows you to easily register and resolve classes and inject dependencies into functions with automatic dependency resolution.
⚡️ No magic. No runtime patching. Just clean, type-safe DI.
@component
decorator@inject
decoratorpoetry add fusebox
from fusebox import Container, component
@component
class ServiceA:
def greet(self):
return "Hello from A"
@component
class ServiceB:
def __init__(self, service_a: ServiceA):
self.service_a = service_a
def greet_with_service_a(self) -> str:
return f"ServiceB says: {self.service_a.greet()}"
service_b = Container.get(ServiceB)
print(service_b.greet_with_service_a()) # ServiceB says: Hello from A
Bind an abstract base class (ABC) to a concrete implementation:
from abc import ABC, abstractmethod
from fusebox import component, Container
class Greeter(ABC):
@abstractmethod
def greet(self): pass
@component
class HelloGreeter(Greeter):
def greet(self):
return "Hello!"
greeter = Container.get(Greeter)
print(greeter.greet()) # Hello!
@inject
You can also inject dependencies directly into functions using the @inject
decorator:
from fusebox import component, inject, Container
@component
class ServiceA:
def greet(self):
return "Hello from A"
@inject
def greet_with_a(a: ServiceA):
return a.greet()
print(greet_with_a()) # Hello from A
You can combine injected dependencies with explicit parameters:
from fusebox import component, inject, Container
@component
class ServiceA:
def greet(self):
return "Hello from A"
@inject
def greet_with_message(a: ServiceA, message: str):
return f"{a.greet()} - {message}"
# 'a' is injected, 'message' is passed explicitly
print(greet_with_message(message="Welcome!")) # Hello from A - Welcome!
# You can also override injected dependencies
custom_a = ServiceA()
print(greet_with_message(a=custom_a, message="Override!")) # Hello from A - Override!
MIT License. See LICENSE file.
📦 PyPI
💻 GitHub
Pull requests are welcome! Please submit issues and suggestions to help improve the project.
FAQs
A lightweight and Pythonic dependency injection container
We found that fusebox demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.