|
1 | | -# dataclass |
| 1 | +# openinflation-dataclass |
| 2 | + |
| 3 | +Typed `pydantic` models for: |
| 4 | +- product cards (`Card`); |
| 5 | +- category trees (`Category`); |
| 6 | +- geolocation and retail entities (`AdministrativeUnit`, `RetailUnit`, `Schedule`). |
| 7 | + |
| 8 | +The package also includes network serialization helpers: |
| 9 | +- `to_json(value)` to convert model data to transport JSON; |
| 10 | +- `from_json(payload, model)` to restore typed objects from JSON. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```bash |
| 15 | +pip install openinflation-dataclass |
| 16 | +``` |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +```python |
| 21 | +from io import BytesIO |
| 22 | + |
| 23 | +from openinflation_dataclass import ( |
| 24 | + AdministrativeUnit, |
| 25 | + Card, |
| 26 | + Category, |
| 27 | + RetailUnit, |
| 28 | + Schedule, |
| 29 | + from_json, |
| 30 | + to_json, |
| 31 | +) |
| 32 | + |
| 33 | +category = Category(uid="milk", alias="milk", title="Milk", adult=False) |
| 34 | + |
| 35 | +card = Card( |
| 36 | + sku="SKU-001", |
| 37 | + plu="123456", |
| 38 | + source_page_url="https://example.com/product/sku-001", |
| 39 | + title="Milk 1L", |
| 40 | + description="Pasteurized milk", |
| 41 | + adult=False, |
| 42 | + new=True, |
| 43 | + promo=False, |
| 44 | + season=False, |
| 45 | + hit=True, |
| 46 | + data_matrix=True, |
| 47 | + brand="Example", |
| 48 | + producer_name="Example Foods", |
| 49 | + producer_country="RUS", |
| 50 | + composition="Milk", |
| 51 | + meta_data=[], |
| 52 | + expiration_date_in_days=10, |
| 53 | + rating=4.8, |
| 54 | + reviews_count=124, |
| 55 | + price=89.9, |
| 56 | + discount_price=79.9, |
| 57 | + loyal_price=75.9, |
| 58 | + wholesale_price=[], |
| 59 | + price_unit="RUB", |
| 60 | + unit="PCE", |
| 61 | + available_count=15, |
| 62 | + package_quantity=1.0, |
| 63 | + package_unit="LTR", |
| 64 | + categories_uid=[category.uid], |
| 65 | + main_image=BytesIO(b"main-image"), |
| 66 | +) |
| 67 | + |
| 68 | +admin = AdministrativeUnit( |
| 69 | + settlement_type="city", |
| 70 | + name="Moscow", |
| 71 | + alias="moskva", |
| 72 | + country="RUS", |
| 73 | + region="Moscow", |
| 74 | + longitude=37.6176, |
| 75 | + latitude=55.7558, |
| 76 | +) |
| 77 | + |
| 78 | +retail = RetailUnit( |
| 79 | + retail_type="store", |
| 80 | + code="STORE-001", |
| 81 | + address="Example st, 1", |
| 82 | + schedule_weekdays=Schedule(open_from="09:00", closed_from="22:00"), |
| 83 | + schedule_saturday=Schedule(open_from="09:00", closed_from="22:00"), |
| 84 | + schedule_sunday=Schedule(open_from="10:00", closed_from="21:00"), |
| 85 | + temporarily_closed=False, |
| 86 | + longitude=37.6176, |
| 87 | + latitude=55.7558, |
| 88 | + administrative_unit=admin, |
| 89 | + categories=[category], |
| 90 | + products=[card], |
| 91 | +) |
| 92 | + |
| 93 | +payload = to_json(retail) |
| 94 | +restored = from_json(payload, RetailUnit) |
| 95 | +``` |
| 96 | + |
| 97 | +`BytesIO` fields are encoded as base64 strings in JSON and restored back to `BytesIO` on `from_json`. |
| 98 | + |
| 99 | +## Development |
| 100 | + |
| 101 | +```bash |
| 102 | +python -m pip install -e ".[dev]" |
| 103 | +ruff check . |
| 104 | +ruff format --check . |
| 105 | +pytest |
| 106 | +python -m build |
| 107 | +twine check dist/* |
| 108 | +``` |
| 109 | + |
| 110 | +## Publishing to PyPI via Trusted Publisher |
| 111 | + |
| 112 | +The repository contains `.github/workflows/publish.yml` that publishes via OIDC (no API token). |
| 113 | +Optional dry-run publishing is available in `.github/workflows/publish-testpypi.yml`. |
| 114 | + |
| 115 | +1. Create a `pypi` environment in GitHub repository settings. |
| 116 | +2. On PyPI, add a Trusted Publisher for this repository with: |
| 117 | + - Owner: `Open-Inflation` |
| 118 | + - Repository: `dataclass` |
| 119 | + - Workflow: `publish.yml` |
| 120 | + - Environment: `pypi` |
| 121 | +3. Create a GitHub Release (or run `workflow_dispatch`) to publish. |
| 122 | +4. (Optional) Configure a second Trusted Publisher in TestPyPI for `publish-testpypi.yml` |
| 123 | + and environment `testpypi`, then run that workflow for pre-release validation. |
0 commit comments