Skip to main content

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.

Metadata

Release files for vcti-selection 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vcti-selection 2.1.0
File Size Uploaded
vcti_selection-2.1.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vcti-selection 2.1.0
File Interpreter ABI Platform
vcti_selection-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / vcti_selection-2.1.0.tar.gz

Download URL vcti_selection-2.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
671614826b9a9b072f76724a90c9250394ac2c13800d4096f8662313878b885d
BLAKE2b-256 checksum
How to use checksums
d8acfaefed5d1fec9770d7390910dc28674686e81eaaba9abc7353fc889a9089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 17, 2026.

Transparency log

Release files / vcti_selection-2.1.0-py3-none-any.whl

Download URL vcti_selection-2.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d6907ed8449e802e8303cf38a12aec34be0cb9fbacf44abe283324d93571987
BLAKE2b-256 checksum
How to use checksums
b8b7dc59e4d9a3784f178316c1d908a411f8858166bcd9504caf99326acf635a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page