Skip to main content

Transparent access to nested objects dictionary 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.0.tar.gz (21.7 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.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for maproxylib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d91ca802f27dde243bc6d66f5a585c67118502030c529ad03c0fba351aadda4
MD5 edc9feb89951e54c59447426f48b2124
BLAKE2b-256 f03e288f71e112c1c00735b72f41f69dc2c203f9039b6e404427adc8001c04b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for maproxylib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51e9f632a37477b9b581240aa54a92c43da71c5ce5f6681edbfe21ac438107f5
MD5 23c162ab5d826c30cf12e6468a99f66e
BLAKE2b-256 0a4f6da0cefd735cf540ef2c4b4d609416be06fe4da455067ed800b4ab5ab6c3

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