Programming in Python empowered with Nodes DI, implements efficient nodes computation agents and dependency scoping
Project description
NodNod
🧑🧑🧒🧒
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!
🌺
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nodnod-1.0.2.tar.gz.
File metadata
- Download URL: nodnod-1.0.2.tar.gz
- Upload date:
- Size: 143.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5331d09189723a83ded51ed1ce508c7a5e1b142b52dfe14a29479c6a5fe4d9b
|
|
| MD5 |
e550c079d69b0042a1f17222ffb360c3
|
|
| BLAKE2b-256 |
c62e87649e4aa8da73451cc266419dab846a2cfa38f0e5a03677c70ad57419c8
|
File details
Details for the file nodnod-1.0.2-py3-none-any.whl.
File metadata
- Download URL: nodnod-1.0.2-py3-none-any.whl
- Upload date:
- Size: 35.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43933568b47c65147cceca0c1c895c8df3731cbeb4cc7c0eaeb52381bb842b48
|
|
| MD5 |
29d7d69dad73bdce78be51600470e0d2
|
|
| BLAKE2b-256 |
953f5e66071e0e3245e9598ee3666343ac7c7d1c6191b19c92c14274fb6bb276
|