Transparent access to nested objects/dicts fields via descriptors
Project description
🗝️ maproxylib — Mapping Proxy Library
Transparent access to nested objects/dicts fields via descriptors.
maproxylib is a lightweight Python library that allows you to transparently access inner objects/dicts fields as class attributes, using the power of descriptors. Especially useful when working with JSON models, DTOs, complex nested structures, and API responses.
✨ Features
- Simple dot-style access to dictionary values
- Support for deeply nested structures (via
path) - Type hint support (
typing,TypeVar) - Integration with
dataclasses - Read-only fields support
🚀 Installation
Various dependency management tools are supported:
pip
pip install maproxylib
poetry
poetry add maproxylib
uv
uv add maproxylib
💡 Usage Examples
1. Basic Usage
from dataclasses import dataclass, field
from maproxylib import ProxyFieldFactory
params_field = ProxyFieldFactory(storage_name="params")
# Descriptor factory for storage `params`
@dataclass
class MyModel:
params: dict = field(default_factory=dict)
# The storage for `params_field` descriptors
name = params_field[str](default="Guest")
age = params_field[int](default=30)
model = MyModel()
assert model.name == "Guest" # Default value (storage is empty)
model.name = "Alice" # Set values in storage
model.age = 25
assert model.params == {"name": "Alice", "age": 25} # Actual values in storage
2. Nested Fields
from dataclasses import dataclass, field
from maproxylib import ProxyFieldFactory
data_field = ProxyFieldFactory(storage_name="data")
# Descriptor fabric for storage `data`
@dataclass
class User:
data: dict = field(default_factory=dict) # Storage
city = data_field[str](key="address.city", default="Unknown")
# The descriptor key in dot notation represents access to `data["address"]["city"]`
user = User()
user.city = "Moscow" # Same as user.data["address"]["city"] = "Moscow"
assert user.data == {"address": {"city": "Moscow"}}
# The storage contains current values in the required structure
📦 Key Components
| Component | Description |
|---|---|
ProxyField[T] |
A descriptor that provides access to a field |
ProxyFieldFactory(...) |
Factory for creating descriptors with preset parameters |
🧪 Testing
You can easily test with pytest:
uv sync --group dev
uv run pytest
🛠️ Development
To install the package locally in development mode:
uv sync --group dev
uv install -e .
🤝 Contributing
Any suggestions, feature requests, and PRs are welcome!
Feel free to open issues on GitHub 👉 issues
⚖️ License
MIT License – see the LICENSE file for details.
📬 Author
🔗 Links
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 maproxylib-0.1.2.tar.gz.
File metadata
- Download URL: maproxylib-0.1.2.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e269fe5a9730258ba549d8d70f235d0dfaab134b085e9501c80741725b703ac
|
|
| MD5 |
c29e55babd95e224608de1407b46fe83
|
|
| BLAKE2b-256 |
572d0df88cc327652bbe26d264e1db1faad5d4364694a89fef8a417af41fd8e3
|
File details
Details for the file maproxylib-0.1.2-py3-none-any.whl.
File metadata
- Download URL: maproxylib-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d744d565f5d5f717736c2f04ea25a0a380fd0df9436c6a784e908607853d1822
|
|
| MD5 |
a86413bee5c5486e2dbd3157ea72e734
|
|
| BLAKE2b-256 |
bc3aaa8a4c300c5a5fd4557abf2a49096a834953eb98ff0be4c849a0fd9947a0
|