Registry / serialization / catalogue

catalogue

JSON →
library2.0.10pypypi✓ verified 26d ago

catalogue is a tiny, zero-dependencies library designed to simplify the creation of function (or object) registries within your Python code. These registries are particularly useful for making objects easily serializable and customizable, allowing you to reference functions by string identifiers instead of direct object references. Currently at version 2.0.10, it maintains an active release cadence with a focus on Python 3.6+ compatibility.

pip install catalogue
INSTALL
IMPORT
SIG · CATALOGUE
C
catalogue
serializationpythonv2.0.10
Install
1.5s avg
Import
100ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.10 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.106s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.094s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

catalogue
import catalogue
The primary way to interact with the library is through the top-level 'catalogue' module.
create
from catalogue import create
import catalogue.create
While 'create' is a function within the module, it's typically accessed directly after 'import catalogue' as 'catalogue.create()'. Direct import like `from catalogue import create` is also valid for convenience.

This example demonstrates how to create a new registry, register functions using the provided decorator, and then retrieve and use those functions by their string identifiers. This pattern enables extensible and serializable configurations for your library.

import catalogue # YOUR PACKAGE - Define a registry loaders = catalogue.create("my_package", "loaders") # USER CODE - Register custom functions @loaders.register("file_loader") def load_from_file(path): print(f"Loading data from file: {path}") return f"Data from {path}" @loaders.register("db_loader") def load_from_db(query): print(f"Loading data from DB with query: {query}") return f"Data for {query}" # YOUR PACKAGE - Access registered functions def get_data(loader_id, source): loader = loaders.get(loader_id) if loader: return loader(source) else: raise ValueError(f"Unknown loader: {loader_id}") print(get_data("file_loader", "/path/to/data.txt")) print(get_data("db_loader", "SELECT * FROM users")) # List all registered loaders print("All registered loaders:", loaders.get_all())
Debug
Known issues
breakingcatalogue v2.0 and newer versions are not compatible with Python 2.7. For Python 2.7 compatibility, users must stick to catalogue v1.x.
fix
Upgrade to Python 3.6+ or downgrade `catalogue` to a 1.x version if Python 2.7 support is strictly required.
affects: 2.0.0+
gotchaA `v2.1.0` release was briefly tagged and then yanked from PyPI, with development continuing on the `2.0.x` branch. This might lead to confusion if relying solely on GitHub tags for version discovery, or if package managers inadvertently picked up the yanked `2.1.0`.
fix
Always refer to the official PyPI release for the latest stable version. If encountering issues with `2.1.0`, ensure you are on the `2.0.x` branch (currently `2.0.10`).
affects: Potentially affects users attempting to install `v2.1.0` or relying on non-PyPI version discovery methods.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'catalogue'
The 'catalogue' package is not installed in the current Python environment or is not accessible within the Python path.
fix
Install the package using pip: `pip install catalogue`
catalogue.RegistryError: [E893] Could not find function '...' in function registry '...'
An attempt was made to retrieve a function from a 'catalogue' registry using a name that has not been registered, or the module defining the registered function was not imported, preventing its registration.
fix
Ensure the function is correctly decorated with `@your_registry_name.register("your_function_name")` and that the Python module containing this definition is imported and executed before attempting to retrieve it from the registry.
AttributeError: 'Catalog' object has no attribute 'component'
This error indicates that an object, likely an instance of a custom 'Catalog' class (which might internally use or be conceptually related to `catalogue`), was accessed for an attribute named 'component' that does not exist on that object.
fix
Examine the code interacting with the 'Catalog' object to verify the correct attribute name or method call, referring to the API of the specific 'Catalog' class in use.
TypeError: register() missing 1 required positional argument: 'name'
The `@registry.register()` decorator or method was called without providing the mandatory string 'name' argument, which is used to identify the function or object being registered. The `catalogue` library's `register` method explicitly requires a name.
fix
Provide a string name to the register decorator or method, for example: `@your_registry.register("my_function_name")`.
Upgrade
Version history
2.0.10latest on PyPI · released Sep 25, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
catalogue — pip install catalogue · libregistry