Generic ordered collection with named items and policy-based compatibility
Project description
Deck
Generic ordered collection with named items and policy-based compatibility for Python.
Purpose
VCollab applications need ordered collections where items are referenced
by name, support custom ordering, and optionally enforce compatibility
rules. Deck provides this as a lightweight, zero-dependency building
block.
Installation
pip install vcti-deck
Quick Start
Basic Deck
from vcti.deck import Deck
deck = Deck[str]()
deck.add("header", "Welcome")
deck.add("body", "Content")
deck.add("footer", "Copyright")
deck.get("header") # "Welcome"
deck.has("body") # True
"footer" in deck # True
len(deck) # 3
list(deck) # ["Welcome", "Content", "Copyright"]
Custom Ordering
deck.set_order(["footer", "header"])
list(deck) # ["Copyright", "Welcome"] — body skipped
deck.ids() # ["footer", "header"]
deck.clear_order()
list(deck) # ["Welcome", "Content", "Copyright"] — insertion order
PolicyBoundDeck
Use PolicyBoundDeck when items must satisfy compatibility rules:
from enum import StrEnum, auto
from vcti.deck import PolicyBoundDeck, CompatibilityPolicy
class LayerKind(StrEnum):
IMAGE = auto()
VECTOR = auto()
class Layer:
def __init__(self, kind: LayerKind):
self.kind = kind
class SameKindPolicy(CompatibilityPolicy[LayerKind, Layer]):
def is_compatible(self, item: Layer, deck_type: LayerKind) -> bool:
return item.kind == deck_type
image_deck = PolicyBoundDeck(deck_type=LayerKind.IMAGE, policy=SameKindPolicy())
image_deck.add("photo", Layer(LayerKind.IMAGE)) # OK
image_deck.add("lines", Layer(LayerKind.VECTOR)) # Raises ValueError
Subclass Compatibility
For simpler cases, override _is_compatible directly:
from vcti.deck import Deck
class PositiveOnlyDeck(Deck[int]):
def _is_compatible(self, item: int) -> bool:
return item > 0
deck = PositiveOnlyDeck()
deck.add("a", 5) # OK
deck.add("b", -1) # Raises ValueError
API Summary
Deck[ItemT]
| Method | Description |
|---|---|
add(id, item, *, replace=False) |
Add item; raise if duplicate unless replace=True |
get(id) |
Return item or None |
has(id) |
Check if ID exists |
remove(id) |
Remove item; raise if missing |
set_order(ids) |
Set custom iteration order |
clear_order() |
Reset to insertion order |
ids() |
IDs in effective order |
items() |
Items in effective order |
PolicyBoundDeck[DeckTypeT, ItemT]
Extends Deck with:
| Attribute/Method | Description |
|---|---|
deck_type |
The type/category this deck is bound to |
policy |
The CompatibilityPolicy instance |
CompatibilityPolicy[DeckTypeT, ItemT]
| Method | Description |
|---|---|
is_compatible(item, deck_type) |
Return True if item is allowed |
Dependencies
None. Standard library only.
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 vcti_deck-1.0.1.tar.gz.
File metadata
- Download URL: vcti_deck-1.0.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b5fb2c3b84f7683ef3b5641e2a711f47e2da4b856832d6c5a02255574481fd1
|
|
| MD5 |
4c05bacedeec9eccf95b11ab13812e9f
|
|
| BLAKE2b-256 |
789acdb297924fb76cd5aa5090a9271268b95d13dbe01505407835ea81ff023a
|
Provenance
The following attestation bundles were made for vcti_deck-1.0.1.tar.gz:
Publisher:
publish.yml on vcollab/vcti-python-deck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_deck-1.0.1.tar.gz -
Subject digest:
3b5fb2c3b84f7683ef3b5641e2a711f47e2da4b856832d6c5a02255574481fd1 - Sigstore transparency entry: 1155564451
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-deck@c4a776d3b3b15e765d981c3e44692464a6a1d304 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vcollab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4a776d3b3b15e765d981c3e44692464a6a1d304 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file vcti_deck-1.0.1-py3-none-any.whl.
File metadata
- Download URL: vcti_deck-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9d75455de4f4272da84b26f806a950fd5a0bcbd2cb4ef15628613614d61ff98
|
|
| MD5 |
bdf78c5d94b8beffe2c6184cfd08ca42
|
|
| BLAKE2b-256 |
73e72a1c650cc97993a565b15f0b9eba1516793d8d52c1faabf28b7a860d419b
|
Provenance
The following attestation bundles were made for vcti_deck-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on vcollab/vcti-python-deck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_deck-1.0.1-py3-none-any.whl -
Subject digest:
d9d75455de4f4272da84b26f806a950fd5a0bcbd2cb4ef15628613614d61ff98 - Sigstore transparency entry: 1155564456
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-deck@c4a776d3b3b15e765d981c3e44692464a6a1d304 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vcollab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4a776d3b3b15e765d981c3e44692464a6a1d304 -
Trigger Event:
workflow_dispatch
-
Statement type: