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
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
Close
Hashes for property_accessor-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1fa1d076034dd126d403c6db76fd80cd632af160b513dcf5ce659bd51760a26 |
|
MD5 | ff1a1f2ceb9a169973126f2e767171a0 |
|
BLAKE2b-256 | d39843d1a992f33490d3b5bec55c3f42b2252520c6f3f4704344d11737288042 |