Skip to main content

A lightweight and powerful dependency injection framework for Python

Project description

NexusDI

PyPI version Python versions PyPI - Status License: MIT

A lightweight and powerful dependency injection framework for Python

NexusDI provides elegant dependency injection with support for multiple lifecycles, automatic dependency resolution, component scanning, and circular dependency handling via lazy proxies.


✨ Key Features

  • 🔄 Multiple Lifecycles: Singleton, transient, and scoped dependencies
  • ⚡ Automatic Resolution: Type-hint based dependency resolution
  • ♻️ Circular Dependencies: Lazy proxies to handle complex graphs
  • 🔍 Component Scanning: Auto-discovery of decorated components
  • 🧵 Thread-Safe: Reliable for concurrent applications
  • 💡 Lightweight: Minimal overhead with maximum flexibility

🚀 Quick Example

from nexusdi import singleton, transient, inject, initialize

@singleton
class DatabaseService:
    def __init__(self):
        self.connection = "database_connection"

@transient
class UserRepository:
    def __init__(self, db_service: DatabaseService):
        self.db = db_service

    def get_user(self, user_id: int):
        return f"User {user_id} from {self.db.connection}"

@inject
def get_user_data(user_repo: UserRepository, user_id: int = 1):
    return user_repo.get_user(user_id)

# Initialize the DI system
initialize()

# Dependencies are automatically injected
result = get_user_data(user_id=123)
print(result)  # "User 123 from database_connection"

📦 Installation

Install NexusDI with pip:

pip install nexusdi

Or with poetry:

poetry add nexusdi

🎯 Core Concepts

Lifecycles

  • singleton: A single instance for the application lifetime
  • transient: A new instance per request
  • scoped: Shared within a defined scope

Injection

  • Use @inject on functions to resolve dependencies automatically

Scanning

  • Decorate classes to enable automatic component discovery

Circular Dependencies

  • NexusDI resolves circular graphs via lazy proxies

🔗 Quick Links


🤝 Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request.


📄 License

This project is licensed under the MIT License – see the LICENSE file for details.


👤 Author

Harrison Alonso Arroyave Gaviria

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

nexusdi-0.0.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexusdi-0.0.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file nexusdi-0.0.1.tar.gz.

File metadata

  • Download URL: nexusdi-0.0.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nexusdi-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e0917202c55a859d2c9e5ff37e57a3d93ed246856b1f4e9d318ff4e98d8d0901
MD5 0b3f52c040079706706875bde875daa9
BLAKE2b-256 cc796c340e75b9e1ae108b944ee27f9cdcdd4df0276dce4824126c6c0778f627

See more details on using hashes here.

File details

Details for the file nexusdi-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: nexusdi-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nexusdi-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 561a26f3d442dd82fd8ba39dc01bf04949016cf69403363aaf317fbffede4fd9
MD5 ac30db0d420ebf75eefbeb86d1fcb4f8
BLAKE2b-256 1dcea6cd7a197f27842e63ffb21bc49e5d0201743ff6eb9cc728cdaf1106f5ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page