
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.
FastInject provides easy dependency injection for Python that makes you code decoupled, testable, uncomplicated and more readable.
Decorate your services with the @injectable
decorator and decorate your function with @inject
. Done!
Your function will now be injected with instances of the required service.
pip install fastinject
Injecting services
Inject services that depend on one another
Use the service registy imperatively to get and set dependencies on the fly
Use multiple registries?
Register similar services?
Below details a
We have a service that we want to inject, so we mark it injectable
with a decorator:
import time, datetime
from fastinject import injectable
@injectable() # <-- Just add this decorator to declare the TimeStamp service to be injectable
class TimeStamp:
ts: float
def __init__(self) -> None:
self.ts = time.time()
@property
def datetime_str(self) -> str:
return datetime.datetime.fromtimestamp(self.ts).strftime("%Y-%m-%d %H:%M:%S")
Step 2: Use the service in a function that is injected in
from fastinject import inject
@inject() # <-- This decorator will inject required services in this function
def function_with_injection(ts: TimeStamp):
print(f"In the injected function, the current time is {ts.datetime_str}.")
if __name__ == "__main__":
function_with_injection()
pip install fastinject
The source code is currently hosted on GitHub at: https://github.com/mike-huls/fastinject
Binary installers for the latest released version are available at the Python Package Index (PyPI).
FastInject has one major dependency: injector
. FastInject aims to build on injector
by making it easier to use.
🔨 Under construction
Find the changelog and list of upcoming features here.
Contributions are always welcome; feel free to submit bug reports, bug fixes, feature requests, documentation improvements or enhancements!
FAQs
Easy dependency injection in Python.
We found that fastinject 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.