Skip to main content

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.12+ 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:

  • KeyBuilder to generate keys from ItemSpecification objects.
  • KeyParser to parse keys back into ItemSpecification objects.

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 root ItemSpecification.
  • 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.py
  • tests/test_item_specification_deserialization.py

Error Handling

  • KeyParser.parse(key) validates input and raises a ValueError for invalid format and a RuntimeError for 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mixam_sdk-0.1.4.tar.gz (48.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mixam_sdk-0.1.4-py3-none-any.whl (102.9 kB view details)

Uploaded Python 3

File details

Details for the file mixam_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: mixam_sdk-0.1.4.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

Hashes for mixam_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 29a8dcc1230dd67363a16e21eb7218a7138de55372b66d57a649922decb0d043
MD5 7d1f3c34b96e06104194731de42f9133
BLAKE2b-256 27d8b4ea35cab14ff851391f52ee590cce177255d4b1417874c73e4c50a6040a

See more details on using hashes here.

File details

Details for the file mixam_sdk-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: mixam_sdk-0.1.4-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

Hashes for mixam_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 051ea1654240813b1f8448701548245d02cb744dc3bdf927fea911f4f2b4f644
MD5 e959b692942e1f7fedcab19d762ec0f4
BLAKE2b-256 874803d7896d459a811437b261b199a75e2c1301d94f9aea9f0547e1119079ea

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