Skip to main content

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 one 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

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.6.3.tar.gz (30.0 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.6.3-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for linkd-0.6.3.tar.gz
Algorithm Hash digest
SHA256 befd146a48eb3db9662209fcfa48f460c8dc9e9b688be6b1091f3495dbca7058
MD5 ec81c32b64a642957d7dd53546b8e8eb
BLAKE2b-256 4cfbbed11523e6417d0c67f7e7c179c132cb02af0a81e03b5616ddb19997813d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for linkd-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ed6199fbfd1f5320f561e8a1e360ec205a921f9d48fa79169208fe6f9fa46a
MD5 1c26897a1433e697b04e3658d406e139
BLAKE2b-256 ab7159c187ffa63d14103f01f32e8183b9ca8d6a8b860f58ed17856d2dc8ffc5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.4

2 files

This release

0.6.3 This release

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page