Skip to main content

Generic plugin registry with typed descriptors and attribute-based filtering for Python

Project description

Plugin Catalog

Generic plugin registry with typed descriptors and attribute-based filtering for Python.

Installation

pip install vcti-plugin-catalog>=1.0.1

In pyproject.toml dependencies

dependencies = [
    "vcti-plugin-catalog>=1.0.1",
]

Quick Start

from vcti.lookup import Rule
from vcti.plugincatalog import Descriptor, Registry

# Define your plugin type
class Parser:
    def __init__(self, extensions: list[str]):
        self.extensions = extensions

# Create descriptors with metadata
csv_parser = Descriptor(
    id="csv",
    name="CSV Parser",
    instance=Parser([".csv"]),
    attributes={"file_type": "text", "streaming": True},
)

json_parser = Descriptor(
    id="json",
    name="JSON Parser",
    instance=Parser([".json"]),
    attributes={"file_type": "text", "streaming": False},
)

binary_parser = Descriptor(
    id="hdf5",
    name="HDF5 Parser",
    instance=Parser([".h5", ".hdf5"]),
    attributes={"file_type": "binary", "streaming": False},
)

# Build a registry
registry = Registry()
registry.register_many([csv_parser, json_parser, binary_parser])

# Lookup by ID
parser = registry.get("csv").instance

# Filter by attributes
text_parsers = registry.lookup.filter([Rule("file_type", "==", "text")])
# [csv_parser_desc, json_parser_desc]

# Multiple rules (AND)
streaming = registry.lookup.filter([
    Rule("file_type", "==", "text"),
    Rule("streaming", "==", True),
])
# [csv_parser_desc]

# OR filtering
subset = registry.lookup.filter_any([
    Rule("file_type", "==", "binary"),
    Rule("streaming", "==", True),
])
# [csv_parser_desc, hdf5_parser_desc]

# First match
first = registry.lookup.first([Rule("file_type", "==", "text")])

Core API

Descriptor[T]

Generic container holding plugin metadata and instance:

Attribute Type Description
id str Unique identifier
name str Human-readable name
instance T The plugin instance
description str | None Optional description
attributes dict[str, Any] Filterable metadata

Registry[D]

Collection manager for descriptors:

Method Description
register(descriptor) Add a descriptor
register_many(descriptors) Add multiple descriptors
unregister(id) Remove a descriptor
unregister_many(ids) Remove multiple descriptors
get(id) Retrieve by ID (raises EntryNotFoundError)
find(id) Retrieve by ID or return None
all() List all descriptors
ids() List all IDs
lookup Cached Lookup for attribute filtering
create_lookup() New independent Lookup instance
copy() Shallow copy of the registry
clear() Remove all descriptors
isolated(preload=) Context manager for test isolation

The registry also supports in, len(), and for ... in iteration.

Filtering

The registry.lookup property returns a vcti.lookup.Lookup instance that filters against descriptor .attributes:

from vcti.lookup import Rule

# AND — all rules must match
registry.lookup.filter([Rule("type", "==", "text"), Rule("active", "==", True)])

# OR — any rule matches
registry.lookup.filter_any([Rule("type", "==", "text"), Rule("type", "==", "csv")])

# NOT — exclude matches
registry.lookup.exclude([Rule("deprecated", "==", True)])

# First match
registry.lookup.first([Rule("type", "==", "text")])

See vcti-lookup for the full filtering API including operators, modifiers, and more.

Lifecycle

# Safe lookup (returns None instead of raising)
desc = registry.find("maybe-missing")

# Remove a plugin
registry.unregister("hdf5")

# Remove several at once
registry.unregister_many(["csv", "json"])

# Iterate over all registered descriptors
for desc in registry:
    print(desc.id, desc.name)

Test Isolation

with Registry.isolated(preload=[csv_parser, json_parser]) as test_reg:
    assert len(test_reg) == 2
    test_reg.unregister("csv")
    assert len(test_reg) == 1
# test_reg is discarded — the original registry is untouched

Dependencies

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

vcti_plugin_catalog-1.0.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

vcti_plugin_catalog-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file vcti_plugin_catalog-1.0.1.tar.gz.

File metadata

  • Download URL: vcti_plugin_catalog-1.0.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vcti_plugin_catalog-1.0.1.tar.gz
Algorithm Hash digest
SHA256 192074f20ae8e3452805eb8d298cf4e37000ca6bc8cf86d176871cfc48f8e3fc
MD5 1b8b425dbada2291134c2963c3eaf68a
BLAKE2b-256 c4191be3138c8208e9881ecb71a3bb0a7b126f33496d4aadcc53e52b7613c518

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_plugin_catalog-1.0.1.tar.gz:

Publisher: publish.yml on vcollab/vcti-python-plugin-catalog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcti_plugin_catalog-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for vcti_plugin_catalog-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30e508fa03f9a97f281509ac719a52e80ecc6bfe5c874b9601c7b51e8f17457f
MD5 5a26c37edc501284d4df57ca9674abb8
BLAKE2b-256 848a0e0eb178176784e40b16d6c8476dc0090ee62eac42263c3ea28a27fba38c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_plugin_catalog-1.0.1-py3-none-any.whl:

Publisher: publish.yml on vcollab/vcti-python-plugin-catalog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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