Recursive Namespace. An extension of SimpleNamespace. Enhance get/set and parse from JSON
Project description
RecursiveNamespaceV2
Description
RecursiveNamespaceV2 extends Python's SimpleNamespace to make nested dicts easy to work with using attribute access, dict access, and chain-keys.
Full documentation: https://recursivenamespacev2.readthedocs.io/
Key features:
- Recursive conversion of nested dicts/lists
- Attribute and dict access (
rn.aandrn["a"]) - Chain-key access (
rn.val_get("a.b.c")) - Array indexing and append syntax (
items[].0,items[].#) - Typed, zero-dependency, pure Python
Installation
pip install RecursiveNamespaceV2
Or with uv:
uv add RecursiveNamespaceV2
For development from source:
git clone https://github.com/pasxd245/RecursiveNamespaceV2.git
cd RecursiveNamespaceV2
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[test]"
Quick Start
from recursivenamespace import RNS # or RecursiveNamespace
data = {
'name': 'John',
'age': 30,
'address': {
'street': '123 Main St',
'city': 'Anytown'
},
'friends': ['Jane', 'Tom']
}
rn = RNS(data)
print(rn.address.city) # Anytown
print(rn["friends"][1]) # Tom
# Chain-key access
rn._.val_set("address.zip", "12345")
print(rn._.val_get("address.zip")) # 12345
# Convert back to dict
data2 = rn._.to_dict()
print(data2["address"]["city"]) # Anytown
Accessing methods when data keys collide
User data often contains keys like "items", "keys", "update", or
"to_dict". These names share namespace with library methods, so the
library keeps them reachable from one canonical place: the obj._
proxy.
- Data with method-name keys is accepted.
RNS({"items": [...]})works; the value is stored underobj["items"]andobj.items. ADeprecationWarningreminds you that the matching method must now be called asobj._.items(). - Direct calls to the legacy methods (
obj.to_dict(),obj.items(), …) also emitDeprecationWarningand forward to the proxy. They will be removed in v0.1.0 (the first stable release); migrate toobj._.<method>(...)before then. _itself is reserved. Data keys named"_"raiseKeyError.
rn = RNS({"name": "John"})
# Preferred (silent):
rn._.to_dict()
rn._.val_set("address.zip", "12345")
# Also works — class-level, useful in tests and tooling:
RNS._.to_dict(rn)
# Legacy (works but warns):
rn.to_dict() # DeprecationWarning
See docs/guides/method-proxy.rst for
the full migration plan and
examples/advanced/13_method_proxy.py
for a runnable example.
Examples
See the examples/ directory for 15 runnable examples organized by difficulty (basic, intermediate, advanced, real-world).
Testing
To run tests, navigate to the project's root directory and execute:
uv run pytest -s
# or with coverage:
uv run coverage run -m pytest
# to generate html report:
uv run coverage html
Release
Versions are derived automatically from git tags (via hatch-vcs):
git tag -a v1.2.3 -m "v1.2.3"
git push --tags
CI automatically builds, publishes to PyPI (OIDC trusted publishing), and creates a GitHub Release with auto-generated notes.
Contributing
Contributions to the RecursiveNamespace project are welcome! Please ensure that any pull requests include tests covering new features or fixes. See CONTRIBUTING.md for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Transparency
AI-assisted development (e.g., Claude Code, Copilot) was used for scaffolding and iteration.
Project details
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 recursivenamespacev2-0.0.4.tar.gz.
File metadata
- Download URL: recursivenamespacev2-0.0.4.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c610a96928e1fc8ed13cbddddff463381dd8e4fdd798a8ceba985d1cce94ca9f
|
|
| MD5 |
c1f9e7b1b4b6a673849e3e2c234055e4
|
|
| BLAKE2b-256 |
33ab86f204bc0da1ef06c35c3287c7234c6956e322d8a12a0fa77897e5cd0e21
|
Provenance
The following attestation bundles were made for recursivenamespacev2-0.0.4.tar.gz:
Publisher:
publish.yml on pasxd245/RecursiveNamespaceV2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
recursivenamespacev2-0.0.4.tar.gz -
Subject digest:
c610a96928e1fc8ed13cbddddff463381dd8e4fdd798a8ceba985d1cce94ca9f - Sigstore transparency entry: 1632949059
- Sigstore integration time:
-
Permalink:
pasxd245/RecursiveNamespaceV2@16769f5502189964ede98293324b8e9c2bfb95e7 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/pasxd245
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16769f5502189964ede98293324b8e9c2bfb95e7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file recursivenamespacev2-0.0.4-py3-none-any.whl.
File metadata
- Download URL: recursivenamespacev2-0.0.4-py3-none-any.whl
- Upload date:
- Size: 15.2 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 |
80bb06eca2f9a1280b34dd7c5ec441bc020f7d31c12c88da5b531a11f1add99f
|
|
| MD5 |
022d9b1f351eaf95e3c575635258942f
|
|
| BLAKE2b-256 |
58c0dda5cea21a673dcc0cec698a4c3a7937fefb9338e7d903da96cc9ab89f2e
|
Provenance
The following attestation bundles were made for recursivenamespacev2-0.0.4-py3-none-any.whl:
Publisher:
publish.yml on pasxd245/RecursiveNamespaceV2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
recursivenamespacev2-0.0.4-py3-none-any.whl -
Subject digest:
80bb06eca2f9a1280b34dd7c5ec441bc020f7d31c12c88da5b531a11f1add99f - Sigstore transparency entry: 1632949082
- Sigstore integration time:
-
Permalink:
pasxd245/RecursiveNamespaceV2@16769f5502189964ede98293324b8e9c2bfb95e7 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/pasxd245
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16769f5502189964ede98293324b8e9c2bfb95e7 -
Trigger Event:
push
-
Statement type: