Skip to main content

A powerful async-only dependency injection framework for Python.

Project description

PyPI codecov

Overview

Linkd is a powerful dependency-injection framework for asyncio-based Python applications.

This library aims to provide an easy way for framework developers to provide dependency-injection functionality, while also being suitable for use with standalone applications with a little bit more work.

For an example of linkd in action, have a look at hikari-lightbulb which uses it to provide all dependency injection functionality.

Installation

Use the package manager pip to install linkd.

pip install linkd

Usage

Standalone

The most basic usage of linkd involves three main steps:

  • Creating a DependencyInjectionManager and registering dependencies
  • Setting up an injection context
  • Enabling injection on a function

An example of all the above can be seen below:

import asyncio

import linkd

# create a manager instance
manager = linkd.DependencyInjectionManager()
# register a dependency to on of the manager's registries
manager.registry_for(linkd.Contexts.ROOT).register_value(str, "thomm.o")

# enable injection on a function with the inject decorator
@linkd.inject
async def greet(who: str) -> str:
    # the 'who' parameter will be injected by linkd
    return f"hello {who}"


# use the contextual decorator to automatically set up an injection context
@manager.contextual(linkd.Contexts.ROOT)
async def main() -> None:
    # call the injected method
    print(await greet())


if __name__ == "__main__":
    asyncio.run(main())

Supported Framework

Linkd currently supports the following frameworks (click to jump to example usage):

If your framework isn't mentioned here, feel free to open an issue requesting support!

Issues

If you find any bugs, issues, or unexpected behaviour while using the library, you should open an issue with details of the problem and how to reproduce if possible. Please also open an issue for any new features you would like to see added.

Contributing

Pull requests are welcome. For major changes, please open an issue/discussion first to discuss what you would like to change.

Please try to ensure that documentation is updated if you add any features accessible through the public API.

If you use this library and like it, feel free to sign up to GitHub and star the project, it is greatly appreciated and lets me know that I'm going in the right direction!

Links

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

linkd-0.2.1.tar.gz (44.9 kB view details)

Uploaded Source

Built Distribution

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

linkd-0.2.1-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file linkd-0.2.1.tar.gz.

File metadata

  • Download URL: linkd-0.2.1.tar.gz
  • Upload date:
  • Size: 44.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for linkd-0.2.1.tar.gz
Algorithm Hash digest
SHA256 48879ec0bc5490107bd3d9e62bba2c5490531c368794b7fb28f01afea37eed17
MD5 e08dfbc395942c89f37845d5ae8993d4
BLAKE2b-256 2f5e65e569aeb37f7d06368468472bf8329cf31d6fdc53a0bf7f7a73982fb65b

See more details on using hashes here.

File details

Details for the file linkd-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: linkd-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for linkd-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 517e136b57e1146a366a82ff2944876053ba41761976b3b47d7070c9ea5f1d71
MD5 79e13504521f690a38ebc3cb99b65158
BLAKE2b-256 aec394c0dc294de2384fd949b62ac978f7b2a49a8e3301080e3b65652a4815de

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