VCollab Selection - generic single-select container for keyed options
Project description
Selection
Generic single-select container for keyed options.
Overview
vcti-selection provides Selection[T], a small generic container
for managing a collection of options where exactly one option can be
selected at a time. Options are stored by string keys and the selected
option can be changed, cleared, or removed at any time.
Typical uses are modelling UI single-choice state (theme, view mode, current dataset) and tracking the "active" item among several. It has zero dependencies and is not thread-safe — callers synchronize if needed.
Installation
pip install vcti-selection
In requirements.txt
vcti-selection>=2.1.0
In pyproject.toml dependencies
dependencies = [
"vcti-selection>=2.1.0",
]
Quick Start
from vcti.selection import Selection
# Construct from a mapping — first key is auto-selected
themes = Selection[str]({
"dark": "Dark Theme",
"light": "Light Theme",
"system": "System Theme",
})
print(themes.selected) # "Dark Theme"
print(themes.selected_key) # "dark"
themes.select("light")
print(themes.selected) # "Light Theme"
# Cycle through keys in insertion order, wrapping at the ends
themes.select_next() # "system"
themes.select_next() # "dark" (wrapped)
# Clear the selection; deselect() returns the previous key
previous = themes.deselect()
print(previous) # "dark"
print(themes.selected) # None
Holding any value type
from dataclasses import dataclass
from vcti.selection import Selection
@dataclass
class View:
title: str
renderer: str
views = Selection[View]({
"plot": View("Plot view", "matplotlib"),
"table": View("Table view", "pandas"),
}, selected="table")
active = views.selected # View(title="Table view", renderer="pandas")
Dict-like access
sel = Selection[str]({"a": "Alpha", "b": "Beta"})
"a" in sel # True
sel["a"] # "Alpha"
sel.get("missing", "—") # "—"
list(sel.keys()) # ["a", "b"]
list(sel.items()) # [("a", "Alpha"), ("b", "Beta")]
for key in sel: ... # iterates keys
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_selection-2.1.0.tar.gz.
File metadata
- Download URL: vcti_selection-2.1.0.tar.gz
- Upload date:
- Size: 9.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 |
671614826b9a9b072f76724a90c9250394ac2c13800d4096f8662313878b885d
|
|
| MD5 |
6e7b26de0552befa7aeec5eb670c2a24
|
|
| BLAKE2b-256 |
d8acfaefed5d1fec9770d7390910dc28674686e81eaaba9abc7353fc889a9089
|
Provenance
The following attestation bundles were made for vcti_selection-2.1.0.tar.gz:
Publisher:
publish.yml on vcollab/vcti-python-selection
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_selection-2.1.0.tar.gz -
Subject digest:
671614826b9a9b072f76724a90c9250394ac2c13800d4096f8662313878b885d - Sigstore transparency entry: 1324028396
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-selection@d4329f8b5ce75087831c49049de0191fb14547f3 -
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@d4329f8b5ce75087831c49049de0191fb14547f3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file vcti_selection-2.1.0-py3-none-any.whl.
File metadata
- Download URL: vcti_selection-2.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 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 |
0d6907ed8449e802e8303cf38a12aec34be0cb9fbacf44abe283324d93571987
|
|
| MD5 |
bb0b742206ed45a62fb6032f3af45cc9
|
|
| BLAKE2b-256 |
b8b7dc59e4d9a3784f178316c1d908a411f8858166bcd9504caf99326acf635a
|
Provenance
The following attestation bundles were made for vcti_selection-2.1.0-py3-none-any.whl:
Publisher:
publish.yml on vcollab/vcti-python-selection
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vcti_selection-2.1.0-py3-none-any.whl -
Subject digest:
0d6907ed8449e802e8303cf38a12aec34be0cb9fbacf44abe283324d93571987 - Sigstore transparency entry: 1324028434
- Sigstore integration time:
-
Permalink:
vcollab/vcti-python-selection@d4329f8b5ce75087831c49049de0191fb14547f3 -
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@d4329f8b5ce75087831c49049de0191fb14547f3 -
Trigger Event:
workflow_dispatch
-
Statement type: