Typed attributes engine for the Stapel framework
Project description
stapel-attributes
Typed attributes engine for the Stapel framework — a polymorphic type system for attribute ("feature") configurations: an open registry of feature types, Config/DTO/DAO layering per type, polymorphic DRF serializers with OpenAPI schemas, and a structured value-validation pipeline.
This is an L1 library, not a module: it ships no models, migrations,
views, urls or comm surface. Both stapel-categories (attribute schema) and
stapel-listings (attribute values) import it — the code both need
synchronously lives one layer down, like stapel-core itself.
Provenance: port of the categories/feature_types engine and the
ads validation pipeline from waylot-catalog (see CHANGELOG for what was
fixed in transit).
Install
pip install stapel-attributes
No INSTALLED_APPS entry, no urls — just import it:
from stapel_attributes import (
FeatureDef,
validate_dto,
normalize_to_dao,
validate_dto_structured,
)
configs = [
FeatureDef(slug="mileage", config={"type": "int", "min": 0, "postfix": "km"}),
FeatureDef(slug="condition", config={"type": "bool"}, mandatory=True),
]
payload = {"mileage": {"type": "int", "value": 120000},
"condition": {"type": "bool", "value": True}}
validate_dto(configs, payload) # raises ValidationError on failure
dao = normalize_to_dao(configs, payload) # {"mileage": {"type": "int", "value": 120000, "postfix": "km", "order": 0}, ...}
result = validate_dto_structured(configs, payload) # machine-readable batch result
Built-in types
int, float, string, bool, hex_color, select, date, header,
hierarchical_select. Each type is a plugin: a Config dataclass (schema), a
DTO (client input), a DAO (stored value + display metadata) and a handler
(BaseFeatureType[TConfig, TDto, TDao]).
Marketplace-specific types (size grids, convertible units, ...) are not shipped — hosts register their own via the open registry (see MODULE.md for the worked example).
Settings
All configuration lives in the STAPEL_ATTRIBUTES namespace (dict setting,
flat setting, or env var — resolved lazily):
| Key | Default | Meaning |
|---|---|---|
EXTRA_TYPES |
[] |
Dotted paths of extra feature types, merged over the built-ins (each entry: a BaseFeatureType subclass or a module that registers types on import). |
Structured validation
Every validation failure carries a machine code end-to-end
(ValidationErrorCode) via FeatureValidationError — no message parsing.
Batch validators return ValidationBatchResult rows with error,
ref_value, localizable_error (an error.400.feature_* key) and params.
Extension points
See MODULE.md — the agent-facing map of every fork-free seam (settings, the type registry, serializer factories, translation-key hooks).
Development
pip install -e . && pip install pytest pytest-django ruff
./setup-hooks.sh
pytest tests/
License
MIT
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 stapel_attributes-0.1.1.tar.gz.
File metadata
- Download URL: stapel_attributes-0.1.1.tar.gz
- Upload date:
- Size: 51.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
308556a621c2426b8b2eb8e31753581349378fcc524d162bf0f5dc2e72c3eb75
|
|
| MD5 |
c73c637b0dc66d67610fb8c207c0e15e
|
|
| BLAKE2b-256 |
fa40dfbfced626473145db6f46a6533639385e83234e675bde55664c791f5b30
|
Provenance
The following attestation bundles were made for stapel_attributes-0.1.1.tar.gz:
Publisher:
publish.yml on usestapel/stapel-attributes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stapel_attributes-0.1.1.tar.gz -
Subject digest:
308556a621c2426b8b2eb8e31753581349378fcc524d162bf0f5dc2e72c3eb75 - Sigstore transparency entry: 2069520218
- Sigstore integration time:
-
Permalink:
usestapel/stapel-attributes@10d462f93dead55b9b9c15413e9f6017fa143c72 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/usestapel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@10d462f93dead55b9b9c15413e9f6017fa143c72 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stapel_attributes-0.1.1-py3-none-any.whl.
File metadata
- Download URL: stapel_attributes-0.1.1-py3-none-any.whl
- Upload date:
- Size: 77.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08fccc56c028b0c5f69ae885c3b3c63eb8feebdad30c77a638c8379e928e3215
|
|
| MD5 |
6cd37954cdf3b8e6606099df9cbb808b
|
|
| BLAKE2b-256 |
c9bad0d3cae5c54f091b7dab05a0165803ce301e2e0ecf1ab8b9525e3a9f0dbd
|
Provenance
The following attestation bundles were made for stapel_attributes-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on usestapel/stapel-attributes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stapel_attributes-0.1.1-py3-none-any.whl -
Subject digest:
08fccc56c028b0c5f69ae885c3b3c63eb8feebdad30c77a638c8379e928e3215 - Sigstore transparency entry: 2069520298
- Sigstore integration time:
-
Permalink:
usestapel/stapel-attributes@10d462f93dead55b9b9c15413e9f6017fa143c72 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/usestapel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@10d462f93dead55b9b9c15413e9f6017fa143c72 -
Trigger Event:
push
-
Statement type: