A declarative Python library for building computation DAGs
Project description
formularity-dag
A declarative Python framework for building computation/formula DAGs (Directed Acyclic Graphs).
Installation
pip install formularity-dag
# With JSON serialization support
pip install formularity-dag[json]
Quick Start
from formularity_dag import InputPlaceholder, ContextPlaceholder, compute, formula_dataclass
# Define a dataclass for structured data
@formula_dataclass
class TaxConfig:
rate: float = 0.1
name: str = "Sales Tax"
# Declare inputs
price = InputPlaceholder("price", float, "Item price", default_val=10.0)
quantity = InputPlaceholder("quantity", int, "Number of items", default_val=1)
# Declare context (environment parameters)
tax_config = ContextPlaceholder("tax_config", TaxConfig, "Tax configuration", default_val=TaxConfig())
# Define computations - dependencies are automatically wired by parameter names
@compute
def subtotal(price, quantity):
return price * quantity
@compute
def tax_amount(subtotal, tax_config):
return subtotal * tax_config.rate
@compute(is_output=True)
def total(subtotal, tax_amount):
return subtotal + tax_amount
Evaluating the Graph
# The graph is automatically created in the module
graph = __compute_graph__
# Evaluate with inputs
result = graph.evaluate({
"price": 25.0,
"quantity": 3,
"tax_config": {"rate": 0.08, "name": "State Tax"}
})
print(result['outputs']) # {'total': 81.0}
print(result['state']) # {'subtotal': 75.0, 'tax_amount': 6.0, 'total': 81.0}
Features
- Declarative syntax: Define inputs and computations, let the framework handle wiring
- Automatic dependency resolution: Parameter names match node names automatically
- Type hints support: Full support for Python type annotations
- Dataclass integration: First-class support for dataclasses with optional JSON serialization
- Input/Context separation: Distinguish between user inputs and environment configuration
- Output marking: Tag specific nodes as final outputs
API Reference
Placeholders
InputPlaceholder(name, dtype, description, default_val, is_required)- Declare an input nodeContextPlaceholder(name, dtype, description, default_val, is_required)- Declare a context node
Decorators
@compute- Register a computation node@compute(is_output=True)- Register as an output node@compute(mapping={'param': 'node_name'})- Custom parameter-to-node mapping@formula_dataclass- Combined@dataclass+@dataclass_jsondecorator
Utilities
is_dataclass_type(dtype)- Check if a type is a dataclassdataclass_to_dict(obj)- Convert dataclass instance to dictdict_to_dataclass(data, dtype)- Convert dict to dataclass instance
License
MIT
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 formularity_dag-0.1.0.tar.gz.
File metadata
- Download URL: formularity_dag-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dce0efdd4aead1c15cbe6543420b33247f7412568a167157e743f70a2cbc8b6
|
|
| MD5 |
36ca43e2933a4582ba0325ab656764c3
|
|
| BLAKE2b-256 |
4bdacc859a7ce135257233a5fefd83e797c3ef07b8adbfbe7d6bf1cbeb0ba930
|
Provenance
The following attestation bundles were made for formularity_dag-0.1.0.tar.gz:
Publisher:
publish-dag.yml on soyvv/formularity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
formularity_dag-0.1.0.tar.gz -
Subject digest:
6dce0efdd4aead1c15cbe6543420b33247f7412568a167157e743f70a2cbc8b6 - Sigstore transparency entry: 870367870
- Sigstore integration time:
-
Permalink:
soyvv/formularity@9cbc0562daa7707f717750f2d86b301b93eede83 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/soyvv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-dag.yml@9cbc0562daa7707f717750f2d86b301b93eede83 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file formularity_dag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: formularity_dag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
396f88ddcccae84a29a983afc9e5c7452340ded4c9e9996913fa95cce2993092
|
|
| MD5 |
3c2c325fc8b26e7de0ed97d7510bd97e
|
|
| BLAKE2b-256 |
608a664ade6ad01ac5aadb89c6b88f2d039bf9c235cb87374fbece08f6c6d90e
|
Provenance
The following attestation bundles were made for formularity_dag-0.1.0-py3-none-any.whl:
Publisher:
publish-dag.yml on soyvv/formularity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
formularity_dag-0.1.0-py3-none-any.whl -
Subject digest:
396f88ddcccae84a29a983afc9e5c7452340ded4c9e9996913fa95cce2993092 - Sigstore transparency entry: 870367872
- Sigstore integration time:
-
Permalink:
soyvv/formularity@9cbc0562daa7707f717750f2d86b301b93eede83 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/soyvv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-dag.yml@9cbc0562daa7707f717750f2d86b301b93eede83 -
Trigger Event:
workflow_dispatch
-
Statement type: