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.2.tar.gz (22.1 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.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for maproxylib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0e269fe5a9730258ba549d8d70f235d0dfaab134b085e9501c80741725b703ac
MD5 c29e55babd95e224608de1407b46fe83
BLAKE2b-256 572d0df88cc327652bbe26d264e1db1faad5d4364694a89fef8a417af41fd8e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for maproxylib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d744d565f5d5f717736c2f04ea25a0a380fd0df9436c6a784e908607853d1822
MD5 a86413bee5c5486e2dbd3157ea72e734
BLAKE2b-256 bc3aaa8a4c300c5a5fd4557abf2a49096a834953eb98ff0be4c849a0fd9947a0

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