freshcrate
Home > RAG & Memory > catalogue

catalogue

Super lightweight function registries for your library

Description

<a href="https://explosion.ai"><img src="https://explosion.ai/assets/img/logo.svg" width="125" height="125" align="right" /></a> # catalogue: Super lightweight function registries for your library `catalogue` is a tiny, zero-dependencies library that makes it easy to **add function (or object) registries** to your code. Function registries are helpful when you have objects that need to be both easily serializable and fully customizable. Instead of passing a function into your object, you pass in an identifier name, which the object can use to lookup the function from the registry. This makes the object easy to serialize, because the name is a simple string. If you instead saved the function, you'd have to use Pickle for serialization, which has many drawbacks. [![tests](https://github.com/explosion/catalogue/actions/workflows/tests.yml/badge.svg)](https://github.com/explosion/catalogue/actions/workflows/tests.yml) [![Current Release Version](https://img.shields.io/github/v/release/explosion/catalogue.svg?style=flat-square&include_prereleases&logo=github)](https://github.com/explosion/catalogue/releases) [![pypi Version](https://img.shields.io/pypi/v/catalogue.svg?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/catalogue/) [![conda Version](https://img.shields.io/conda/vn/conda-forge/catalogue.svg?style=flat-square&logo=conda-forge&logoColor=white)](https://anaconda.org/conda-forge/catalogue) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/ambv/black) ## ⏳ Installation ```bash pip install catalogue ``` ```bash conda install -c conda-forge catalogue ``` > ⚠️ **Important note:** `catalogue` v2.0+ is only compatible with Python 3.6+. > For Python 2.7+ compatibility, use `catalogue` v1.x. ## 👩‍💻 Usage Let's imagine you're developing a Python package that needs to load data somewhere. You've already implemented some loader functions for the most common data types, but you want to allow the user to easily add their own. Using `catalogue.create` you can create a new registry under the namespace `your_package` &rarr; `loaders`. ```python # YOUR PACKAGE import catalogue loaders = catalogue.create("your_package", "loaders") ``` This gives you a `loaders.register` decorator that your users can import and decorate their custom loader functions with. ```python # USER CODE from your_package import loaders @loaders.register("custom_loader") def custom_loader(data): # Load something here... return data ``` The decorated function will be registered automatically and in your package, you'll be able to access all loaders by calling `loaders.get_all`. ```python # YOUR PACKAGE def load_data(data, loader_id): print("All loaders:", loaders.get_all()) # {"custom_loader": <custom_loader>} loader = loaders.get(loader_id) return loader(data) ``` The user can now refer to their custom loader using only its string name (`"custom_loader"`) and your application will know what to do and will use their custom function. ```python # USER CODE from your_package import load_data load_data(data, loader_id="custom_loader") ``` ## ❓ FAQ #### But can't the user just pass in the `custom_loader` function directly? Sure, that's the more classic callback approach. Instead of a string ID, `load_data` could also take a function, in which case you wouldn't need a package like this. `catalogue` helps you when you need to produce a serializable record of which functions were passed in. For instance, you might want to write a log message, or save a config to load back your object later. With `catalogue`, your functions can be parameterized by strings, so logging and serialization remains easy – while still giving you full extensibility. #### How do I make sure all of the registration decorators have run? Decorators normally run when modules are imported. Relying on this side-effect can sometimes lead to confusion, especially if there's no other reason the module would be imported. One solution is to use [entry points](https://packaging.python.org/specifications/entry-points/). For instance, in [spaCy](https://spacy.io) we're starting to use function registries to make the pipeline components much more customizable. Let's say one user, Jo, develops a better tagging model using new machine learning research. End-users of Jo's package should be able to write `spacy.load("jo_tagging_model")`. They shouldn't need to remember to write `import jos_tagged_model` first, just to run the function registries as a side-effect. With entry points, the registration happens at install time – so you don't need to rely on the import side-effects. ## 🎛 API ### <kbd>function</kbd> `catalogue.create` Create a new registry for a given namespace. Returns a setter function that can be used as a decorator or called with a name and `func` keyword argument. If `entry_points=True` is set, the registry will check for [Python entry points](https

Release History

VersionChangesUrgencyDate
2.0.10Imported from PyPI (2.0.10)Low4/21/2026
v2.0.10- Package and test suite updates for Python 3.12 (#66).Low9/25/2023
v2.0.9- Update for compatibility with future Python 3.12 (#62).Low7/24/2023
v1.0.2* Require Python 3.6+.Low10/18/2022
v1.0.1> **Note:** v1.0.1 was deleted from PyPI because it was incompatible with python 2.7, but the package setup did not specify this correctly and yanked packages are not supported by the latest `pip` for python 2.7. The v1.0.2 release is identical to v1.0.1 except for the corrected `python_requires>=3.6`. * Add vendored `importlib_metadata` v3.2.0 for use with Python 3.6-3.7 to avoid breaking changes in newer releases and to avoid conflicts with `importlib_metadata` requirements in other packageLow10/7/2022
v2.0.8* Improve future compatibility with `importlib.metadata` for python 3.10+. * Update tests for compatibility with python 3.10+.Low7/26/2022
v2.0.7* Modify test suite for python 3.10 until `importlib.metadata` differences can be addressed.Low3/22/2022
v2.0.6* Prevent `Registry.find` from failing on Cython modules.Low8/21/2021
v2.0.5* Backport `packages_distributions` from `importlib_metadata`.Low8/13/2021
v2.0.4* Fix conflicts between `catalogue` and `importlib-metadata`Low4/30/2021
v2.0.3* Add vendored `importlib-metadata` v3.2.0 to avoid conflicts with `importlib-metadata` requirements in other packagesLow4/30/2021
v2.0.2* Restrict `importlib-metadata` to `<3.3.0` due to reports of performance regressions and issues with the test suiteLow4/14/2021
v2.0.1Release v2.0.1Low8/27/2020
v2.0.0Release v2.0.0Low1/10/2020
v1.0.0Release v1.0.0Low1/9/2020
v0.2.1Release v0.2.1Low1/8/2020
v0.2.0Release v0.2.0Low12/26/2019
v0.0.8Release v0.0.8Low11/4/2019
v0.0.7Release v0.0.7Low11/4/2019
v0.0.6Release v0.0.6Low11/4/2019
v0.0.5Release v0.0.5Low11/4/2019
v0.0.4Release v0.0.4Low11/2/2019
v0.0.3Release v0.0.3Low11/1/2019
v0.0.2Release v0.0.2Low11/1/2019

Dependencies & License Audit

Loading dependencies...

Similar Packages

azure-search-documentsMicrosoft Azure Cognitive Search Client Library for Pythonazure-template_0.1.0b6187637
apache-tvm-ffitvm ffi0.1.10
luqumA Lucene query parser generating ElasticSearch queries and more !1.0.0
torchaoPackage for applying ao techniques to GPU models0.17.0
banksA prompt programming language2.4.1