Skip to main content

No project description provided

Project description

property_accessor

Python property accessor module util

Installation:

> poetry add property-accessor

Usage

from property_accessor import PropertyAccessor
from dataclasses import dataclass, field


@dataclass
class Category:
    code: str

@dataclass
class Product:

    name: str
    sku: str
    price: float
    categories: list[Category] = field(default=list)


accessor = PropertyAccessor(None)

accessor.set('sku', 't-shirt-01')
accessor.set('name', 't-shirt basic black')
accessor.set('price', 39.9)
accessor.set('categories[0].code', 't-shits')

print(accessor.get('name')) # t-shirt basic black
print(accessor.get('categories[0].code')) # t-shirt


print(accessor.data) # AnonymousObject(sku='t-shirt-01', name='t-shirt basic black', price=39.9, categories=[AnonymousObject(code="t-shirts")])
print(accessor.data.cast(Product)) # Product(sku='t-shirt-01', name='t-shirt basic black', price=39.9, categories=[Category(code="t-shirts")])

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

property_accessor-0.1.0.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

property_accessor-0.1.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

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