Mixam Python SDK: ItemSpecification Core Models & Enums. KeyBuilder & KeyParser For Working With Universal Keys
Project description
Mixam Python SDK
Mixam SDK is a lightweight Python library that helps you build, validate, serialize, and parse print Item Specifications used by Mixam. It provides:
- Core data models and enums to represent product specifications (components, substrates, bindings, sizes, etc.).
- A Universal Key system to serialize an ItemSpecification to a compact string and parse it back reliably.
Installation
- Via pip:
pip install mixam-sdk
- Via Poetry:
poetry add mixam-sdk
Python 3.13+ is required (see pyproject.toml).
Quick Start
Below are minimal examples showing how to work with Item Specifications and the Universal Key.
Create an ItemSpecification and build a Universal Key
from mixam_sdk.item_specification.models.item_specification import ItemSpecification
from mixam_sdk.item_specification.enums.product import Product
from mixam_sdk.item_specification.models.flat_component import FlatComponent
from mixam_sdk.item_specification.enums.component_type import ComponentType
from mixam_sdk.universal_key.models.key_builder import KeyBuilder
# Build a simple spec with one flat component
item = ItemSpecification()
item.copies = 250
# Create a simple flat component
comp = FlatComponent()
comp.component_type = ComponentType.FLAT
# ... populate additional fields supported by FlatComponent as needed ...
item.components.append(comp)
# Build a Universal Key string
key = KeyBuilder().build(item)
print(key)
Parse a Universal Key back into an ItemSpecification
from mixam_sdk.universal_key.models.key_parser import KeyParser
parser = KeyParser()
# Provide a Universal Key string (from earlier build step or an external source)
some_key = "250~10-fl{...}"
parsed = parser.parse(some_key)
print(parsed.copies)
print(parsed.product)
print([c.component_type for c in parsed.components])
If the key does not match the expected format, KeyParser.parse raises a ValueError or RuntimeError indicating the issue.
What is a Universal Key?
A Universal Key is a compact, validated string representation of an ItemSpecification.
- Format (high level):
copies~productId-<component>{<memberTokens>}-<component>{...}
- Example:
250~10-fl{...}-bd{...} - Keys are validated using a strict regex to ensure correctness before parsing.
The SDK provides:
KeyBuilderto generate keys fromItemSpecificationobjects.KeyParserto parse keys back intoItemSpecificationobjects.
Main Concepts
- Enums: Found under
mixam_sdk/item_specification/enums, they define allowed values for products, sizes, colours, laminations, bindings, etc. - Models: Under
mixam_sdk/item_specification/models, they represent components such as flat, folded, cover, bound components, and more, as well as the rootItemSpecification. - Interfaces/Support: Internal helpers for ordering components and mapping model fields to the Universal Key token format.
Explore the tests/ folder for concrete usage patterns and expected behaviours:
tests/test_universal_key.pytests/test_item_specification_deserialization.py
Error Handling
KeyParser.parse(key)validates input and raises aValueErrorfor invalid format and aRuntimeErrorfor parsing failures.- When building keys, ensure your components are populated with required fields; otherwise the builder may not emit expected tokens.
Development
- Run tests:
pytest -q
- Local install for development:
poetry install
poetry run pytest -q
Versioning
The package follows semantic versioning where possible. See pyproject.toml for the current version.
License
Copyright (c) Mixam.
See the repository for license terms or contact developer@mixam.com.
Examples (from tests)
Below are full examples taken directly from the test suite to illustrate the exact formats.
- Universal Key example (Booklet):
10~1-bd{4bt-5c-4f-200p-1st-3sw}-cr{5c-5c+-4f-4l-1st-7sw}
- Matching ItemSpecification JSON example (as used in tests):
{
"itemSpecification": {
"copies": 10,
"product": "BROCHURES",
"components": [
{
"componentType": "BOUND",
"format": 4,
"standardSize": "NONE",
"orientation": "PORTRAIT",
"colours": "PROCESS",
"substrate": {
"typeId": 1,
"weightId": 3,
"colourId": 0
},
"pages": 200,
"lamination": "NONE",
"binding": {
"type": "PUR"
}
},
{
"componentType": "COVER",
"format": 4,
"standardSize": "NONE",
"orientation": "PORTRAIT",
"colours": "PROCESS",
"substrate": {
"typeId": 1,
"weightId": 7,
"colourId": 0
},
"lamination": "GLOSS",
"backColours": "PROCESS",
"backLamination": "NONE"
}
]
}
}
Links
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mixam_sdk-0.1.3.tar.gz.
File metadata
- Download URL: mixam_sdk-0.1.3.tar.gz
- Upload date:
- Size: 48.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56871c858bd90bc8a8b77e26585639bda33dd53938fdc75e61adfafe5d3f9946
|
|
| MD5 |
8e2d88c69254acd6d8f2abb5b66cc899
|
|
| BLAKE2b-256 |
0d88066458fc594ff834eea80c3ebd9d837c3156217c129c8b6016ceef6a9d80
|
File details
Details for the file mixam_sdk-0.1.3-py3-none-any.whl.
File metadata
- Download URL: mixam_sdk-0.1.3-py3-none-any.whl
- Upload date:
- Size: 102.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bda5dea87f80149c1072c6863b289c49b12ce8f82176b8800e3b5deccf24ba94
|
|
| MD5 |
b88a617d10fa62ef106805169504a881
|
|
| BLAKE2b-256 |
6022bf522d11fabce76a52310722e73ce5e73642ad3a57b4fdc7721696000423
|