Modernized bag system for the Genropy framework - hierarchical data container with XML serialization
Project description
genro-bag
An Intermediate Representation for Structured Data
A Bag is an intermediate representation (IR) for hierarchical data in Python.
What is an Intermediate Representation?
In compiler design, an IR is a data structure that sits between source code and machine code. It captures the essential structure while abstracting away format-specific details, making it easier to analyze, transform, and generate output.
The same principle applies to data: configuration files, API responses, documents, and UI structures all share a common shape—named things containing values, organized hierarchically, with metadata attached—but we typically scatter this across dictionaries, classes, JSON, XML, and database rows.
A Bag provides a canonical representation for this common pattern:
flowchart LR
subgraph Sources
JSON[JSON file]
XML[XML file]
API[API response]
DB[Database]
Input[User input]
end
subgraph BAG[" "]
Tree["Unified tree<br/>of named nodes"]
end
subgraph Outputs
HTML[HTML]
XMLout[XML]
DBout[Database]
JSONout[JSON]
UI[UI]
end
JSON --> Tree
XML --> Tree
API --> Tree
DB --> Tree
Input --> Tree
Tree --> HTML
Tree --> XMLout
Tree --> DBout
Tree --> JSONout
Tree --> UI
Why an IR?
Decoupling: Your application logic works with one structure, regardless of input/output formats. Change your data source from XML to JSON? Your code doesn't change.
Uniformity: One access pattern (bag['path.to.value']), one way to attach metadata, one subscription model—instead of learning different APIs for each library.
Transformation: Operate on the structure itself: walk the tree, filter nodes, transform values, validate structure—without knowing if it came from a file, an API, or a database.
Round-tripping: Serialize to XML, JSON, or MessagePack and back, preserving types, attributes, and structure—including lazy-loaded values (resolvers).
The Core Model
Every node in a Bag has:
| Component | Purpose |
|---|---|
| Label | The node's name (key in the hierarchy) |
| Value | The data it holds (any Python value, or another Bag) |
| Attributes | Metadata attached to the node |
| Tag | Optional semantic type (like XML elements) |
Access is path-based: bag['config.database.host'] navigates the hierarchy using dot notation.
Progressive Capability
Bag provides four layers—use only what you need:
| Layer | Purpose | Use When |
|---|---|---|
| Core Bag | Paths, values, attributes, serialization | Always |
| Resolvers | Lazy-loaded, computed values | API calls, DB queries, expensive computations |
| Subscriptions | React to changes | Validation, logging, sync, computed properties |
Interactive Notebooks
Try genro-bag directly in your browser with Google Colab:
| Notebook | Topics |
|---|---|
| Core Bag — Paths, values, attributes, serialization | |
| Resolvers — Lazy loading, caching, custom resolvers | |
| Subscriptions — Events, validation, computed properties |
Install
pip install genro-bag
Documentation
| Resource | Description |
|---|---|
| Full Documentation | Complete guide with examples |
| Why Bag? | Detailed comparison with alternatives |
| Getting Started | Learn the core concepts |
In This Repository
| Directory | Description |
|---|---|
src/genro_bag/ |
Core implementation |
src/genro_bag/resolvers/ |
Built-in resolvers (URL, Directory, OpenAPI, Env, UUID, etc.) |
examples/ |
Usage examples |
tests/ |
Test suite (1800+ tests) |
docs/ |
Sphinx documentation source |
Development
pip install -e ".[dev]"
pytest
License
Apache License 2.0 — see LICENSE for details.
Copyright 2025 Softwell S.r.l. — Genropy Team
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 genro_bag-0.18.3.tar.gz.
File metadata
- Download URL: genro_bag-0.18.3.tar.gz
- Upload date:
- Size: 324.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f36c6d913ee7a94b437c9e27e1ea451081a46caac02d607f4e1d544af2b392ca
|
|
| MD5 |
d6d70e68ba56085db14242fc8b73a3d0
|
|
| BLAKE2b-256 |
22521060b5e06ebea6e7077c9d20ff90b2bcaa3cdfcfce4bd0ed06c4e129a1e5
|
Provenance
The following attestation bundles were made for genro_bag-0.18.3.tar.gz:
Publisher:
publish.yml on genropy/genro-bag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
genro_bag-0.18.3.tar.gz -
Subject digest:
f36c6d913ee7a94b437c9e27e1ea451081a46caac02d607f4e1d544af2b392ca - Sigstore transparency entry: 1664751658
- Sigstore integration time:
-
Permalink:
genropy/genro-bag@682cd8e100ff0978900858a1e9fcf1d76ee33f2e -
Branch / Tag:
refs/tags/v0.18.3 - Owner: https://github.com/genropy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@682cd8e100ff0978900858a1e9fcf1d76ee33f2e -
Trigger Event:
push
-
Statement type:
File details
Details for the file genro_bag-0.18.3-py3-none-any.whl.
File metadata
- Download URL: genro_bag-0.18.3-py3-none-any.whl
- Upload date:
- Size: 88.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
653522944f92488c4f0db1bd45adf120bb82ced4e04b3a4c078f4671c57c1da3
|
|
| MD5 |
d903efcc3a890539ad3767c744c6db16
|
|
| BLAKE2b-256 |
f3b8aa6f2e2c9de72d494d37fbde6947b618a91eed15c7d2a616002d6d1213a4
|
Provenance
The following attestation bundles were made for genro_bag-0.18.3-py3-none-any.whl:
Publisher:
publish.yml on genropy/genro-bag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
genro_bag-0.18.3-py3-none-any.whl -
Subject digest:
653522944f92488c4f0db1bd45adf120bb82ced4e04b3a4c078f4671c57c1da3 - Sigstore transparency entry: 1664751752
- Sigstore integration time:
-
Permalink:
genropy/genro-bag@682cd8e100ff0978900858a1e9fcf1d76ee33f2e -
Branch / Tag:
refs/tags/v0.18.3 - Owner: https://github.com/genropy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@682cd8e100ff0978900858a1e9fcf1d76ee33f2e -
Trigger Event:
push
-
Statement type: