Skip to main content

NodNod

🧑‍🧑‍🧒‍🧒

codecov pypi

about

nodnod is a dependency injection tool

nodnod strives to be effective and simple: it has many agents, but, for example, asyncio agent turns each dependency into a coroutine and yields decomposed dependency net to your loop to solve it the best way possible

nodnod is easy to integrate, be it a framework or a small project

interfaces

composing a set of dependencies is as simple as:

async def main():
    agent = EventLoopAgent.build({Username})

    async with Scope() as scope:
        scope.inject(User, User(id=1, username=Some("arseni")))
        await agent.run(scope, {})

    print(scope[Username])

two objects that define compile-time and runtime are agent and Scope.

  • agent precompiles the dependency graph
  • scope contains dependency roots and defines dependency visibility within one scope. many scopes can be linked in the manner of parent-child or global-local relation. dependencies are made accessible within different scopes

nodnod provides many interfaces to build different kinds of dependencies:

  • polymorphic - node whose resolution may vary

    @polymorphic[float]
    class Ratio:
        @case
        def from_video(cls, video: Video) -> float:
            frame = video.frames[0]
            return frame.width / frame.length
    
        @case
        def from_photo(cls, photo: Photo) -> float:
            return photo.width / photo.length
    
  • scalar node disguises as its result for type checkers

    @scalar_node
    class Username:
        @classmethod
        def __compose__(cls, user: User) -> str:
            return user.username.map_error(lambda _: f"#{user.id}")
    
  • logical or

    @classmethod
    def __compose__(cls, dep: One | Another) -> ...: ...
    
    • can be concurrent: two nodes are racing to deliver their resolution
    • or sequential: if first resolution fails, next one is triggered
  • kungfu funtional types are supported:

    Exceptions can be intercepted:

    @classmethod
    def __compose__(cls, weather: Result[Weather, ConnectionError)): ...
    

    Dependencies can be optional:

    @classmethod
    def __compose__(cls, ratio: Option[Ratio]): ...
    

your contributions are welcome!

🌺

Metadata

Release files for nodnod 1.1.0

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

Source distribution (sdist)

Source distribution for nodnod 1.1.0
File Size Uploaded
nodnod-1.1.0.tar.gz 152.5 kB Details

Built distribution (wheel)

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

Total release size: 193.8 kB

Release files / nodnod-1.1.0.tar.gz

Download URL nodnod-1.1.0.tar.gz
Size 152.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e0acd5432d17436a5a12e4e937c6b413185025da33ffa43b9da76f8d08a5e3f4
BLAKE2b-256 checksum
How to use checksums
6d13bb38dce545d31acac4a4ad3fb91ce09b43b9a818f853f36ba2f00fde3d9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nodnod-1.1.0-py3-none-any.whl

Download URL nodnod-1.1.0-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abcab5ceadbed62c423d4680771a9f876bcd559f959d7275b20b67df5e20ea39
BLAKE2b-256 checksum
How to use checksums
12f24e063e14444ff0c302619ba17fb1400de36faf976b43be84e610c7de11d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

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