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!

🌺

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nodnod-1.1.0.tar.gz (152.5 kB view details)

Uploaded Source

Built Distribution

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

nodnod-1.1.0-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file nodnod-1.1.0.tar.gz.

File metadata

  • Download URL: nodnod-1.1.0.tar.gz
  • Upload date:
  • Size: 152.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for nodnod-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e0acd5432d17436a5a12e4e937c6b413185025da33ffa43b9da76f8d08a5e3f4
MD5 4ce6431e7fa6deff18493642d359235c
BLAKE2b-256 6d13bb38dce545d31acac4a4ad3fb91ce09b43b9a818f853f36ba2f00fde3d9a

See more details on using hashes here.

File details

Details for the file nodnod-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: nodnod-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for nodnod-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abcab5ceadbed62c423d4680771a9f876bcd559f959d7275b20b67df5e20ea39
MD5 55175c26fafcdeaadd96292cad850bc4
BLAKE2b-256 12f24e063e14444ff0c302619ba17fb1400de36faf976b43be84e610c7de11d2

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