Skip to main content

No project description provided

Project description

WireUp

Effortless dependency injection in Python.

1. Set application parameters

container.params.update({
    "db.connection_str": "sqlite://memory",
    "auth.user": os.environ.get("USER"),
    "cache_dir": "/var/cache/",
    "env": os.environ.get("ENV", "dev")
})

2. Register dependencies

@container.register
class DbService:
    def __init__(
        self,
        # Inject a parameter by name
        connection_str: str = wire(param="db.connection_str"),
        # Or by interpolating multiple parameters into a string
        cache_dir: str = wire(expr="${cache_dir}/${auth.user}/db"),
    ):
        self.connection_str = connection_str
        self.cache_dir = cache_dir
        
# Constructor injection is also supported for dataclasses
# resulting in a more compact syntax.
@container.register
@dataclass  
class UserRepository:
    db: DbService # Dependencies may also depend on other dependencies.
    user: str = container.wire(param="auth.user") 

3. Inject

# Decorate all methods where the library must perform injection. 
@app.route("/greet/<str:name>")
@container.autowire
# Classes are automatically injected based on annotated type. 
# Parameters will be located based on the hint given in their default value.
# Unknown arguments will not be processed.
def greet(name: str, user_repository: UserRepository, env: str = wire(param="env")):
  ...

Documentation

For more information read our documentation

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

wireup-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

wireup-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file wireup-0.1.0.tar.gz.

File metadata

  • Download URL: wireup-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.8.17 Linux/5.19.0-42-generic

File hashes

Hashes for wireup-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b3baa9e8a13deba553c99ef38f1346b9626ae9c9c9a8a57bec4e876aa6440243
MD5 6f2597cfaa633745baf351c326813c90
BLAKE2b-256 070da6ba9c232fb1617a23759243d12c2a4389c3812175648ccd7c55df6d1746

See more details on using hashes here.

File details

Details for the file wireup-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wireup-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.8.17 Linux/5.19.0-42-generic

File hashes

Hashes for wireup-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5964666b186e0976f38b65f0cab59d792c04de44e325a308c35c90e546cf58b7
MD5 947ca7da859826a67d104edfa29f5b3c
BLAKE2b-256 16894effde6e510a0094f6cb58f1f4413dfd198a4967ae6c51df7c1b374d4a72

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