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!

Metadata

Release files for linkd 0.6.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linkd 0.6.5
File Size Uploaded
linkd-0.6.5.tar.gz 30.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for linkd 0.6.5
File Interpreter ABI Platform
linkd-0.6.5-py3-none-any.whl Python 3 none any Details

Total release size: 78.4 kB

Release files / linkd-0.6.5.tar.gz

Download URL linkd-0.6.5.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
24b086a0075a34a5bb8e2bf036b0513798cba96d7bc4faed666d160ef043c1c5
BLAKE2b-256 checksum
How to use checksums
67f0572f8ccc85baa7f17dd02b527ef7fa52b4d54769c1ddf15b6c098475ebe2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release files / linkd-0.6.5-py3-none-any.whl

Download URL linkd-0.6.5-py3-none-any.whl
Size 48.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82620a71e36c389c8f7aaad79e920da4cfa23c7259f5663884c1c61bfcb01cfc
BLAKE2b-256 checksum
How to use checksums
53aa76f148898a131cb6e42e06126c77412d6731eb18a0b652535f4279bc66aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release history Release notifications | RSS feed

This release

0.6.5 This release

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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