Skip to main content

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.

PyPI version Python versions License: MIT Build Status


✨ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maproxylib-0.1.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maproxylib-0.1.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file maproxylib-0.1.1.tar.gz.

File metadata

  • Download URL: maproxylib-0.1.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for maproxylib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4fb7213974a30e862ee337b58aa4f736c9fa46f175b0efa3b7a2f149794468f
MD5 ce1b9d2ec592cf3b66be712378208747
BLAKE2b-256 5aff0aa7ae2acd781c79439b69f9478a1c0b7bf037d48e0f78aff5a49557d243

See more details on using hashes here.

File details

Details for the file maproxylib-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for maproxylib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16a41665638fbe6f35fa930f609ae21d4d700177115347e1306dc60a01199755
MD5 2afb4bc7f560e6bea7af3600a7e30869
BLAKE2b-256 92d343536c477be24f043e71bc1c1bfbecc1099bfe91ac0ea1495765b7bb6c94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page