Simple and powerful tagging for Python objects.
Project description
The Python package gentag provides simple and powerful tagging for arbitrary Python objects. After defining your tags and associated objects you can query for the difference, intersection and union of tags to select specific objects. The package is currently tested on cPython 2.6, 2.7, 3.4, 3.5, 3.6 and PyPy (2.7).
Status
While the ideas behind gentag have been floating around in my head since 2012 I didn’t publish this as a standalone Python package until 2018 which explains why I’m publishing the initial version as a beta. Looking ahead towards the future:
It may be that the current version serves my needs fine and at some point I decide to replace the ‘beta’ label with a ‘stable’ label without making any substantive changes.
Releasing gentag is one step in the direction of releasing another Python package that I’ve been thinking about for a very long time now and if I turn out to have trouble integrating gentag into that package I won’t hesitate to make (potentially major) changes to gentag.
Installation
The gentag package is available on PyPI which means installation should be as simple as:
$ pip install gentag
There’s actually a multitude of ways to install Python packages (e.g. the per user site-packages directory, virtual environments or just installing system wide) and I have no intention of getting into that discussion here, so if this intimidates you then read up on your options before returning to these instructions ;-).
Usage
The following sections give an overview of how to get started. For more details about the Python API please refer to the API documentation available on Read the Docs.
Creating a scope
To get started you have to create a Scope object:
>>> from gentag import Scope
>>> tags = Scope()
The purpose of Scope objects is to group together related tags into an evaluation context for tag expressions.
History
The example in the usage section isn’t actually very useful, this is partly because I didn’t want a complicated subject matter to distract readers from usage instructions :-).
The actual use case that triggered the ideas behind gentag presented itself to me in 2012 when I wanted to query a database of more than 200 Linux server names categorized by aspects such as:
The distributor id (a string like ‘debian’ or ‘ubuntu’).
The distribution codename (a string like ‘trusty’ or ‘xenial’).
The server’s role (database, mailserver, webserver, etc).
The server’s environment (production, development).
The easy selection of subsets of servers for my Python programs to operate on quickly evolved into my main interface for selecting groups of servers. Since then I’ve wanted to use similar functionality in other places, but found it too much work to develop one-off solutions. This is how gentag was born.
About the name
The name gentag stands for “generative tags”, because the package allows new tags to be composed (generated) from existing tags. I’d like to thank my colleague Seán Murphy for coming up with this name :-).
Contact
The latest version of gentag is available on PyPI and GitHub. The documentation is hosted on Read the Docs. For bug reports please create an issue on GitHub. If you have questions, suggestions, etc. feel free to send me an e-mail at peter@peterodding.com.
License
This software is licensed under the MIT license.
© 2018 Peter Odding.
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.