Fast data structure for managing tags and metadata with efficient queries
Project description
TagMap
A data structure for managing tags and metadata with support for efficient intersection and union queries. Implemented in C++ with Python bindings via pybind11.
Overview
TagMap provides a dictionary-like container where each key maps to a set of tags. It supports querying for keys that match specific tag combinations using AND (intersection) and OR (union) operations.
Characteristics
- O(1) average case for single tag operations (add, remove, check)
- O(k·m) for AND queries (k = result size, m = avg tags per key)
- O(n) for OR queries (n = total keys matching any tag)
- Inverted index structure for fast queries
- C++ implementation with Python 3.8+ compatibility
Install
Install from PyPI:
pip install tagmap
Requires Python 3.8 or later. Pre-built wheels available for Linux, macOS, and Windows. For platform-specific instructions, see INSTALLATION.md.
Usage
import tagmap
m = tagmap.TagMap()
# Set tags for keys
m["alice"] = {"dev", "python"}
m["bob"] = {"dev", "cpp"}
m["carol"] = ["design", "python"]
# Query: keys with both "dev" AND "python"
m.query("dev", "python") # ['alice']
# Query: keys with "python" OR "ops"
m.query_any("python", "ops") # ['alice', 'carol']
# Check if key has tag
m.has_tag("alice", "python") # True
# Add or remove tags
m.add_tag("alice", "ml")
m.remove_tag("bob", "dev")
Documentation
- API Reference - Complete method documentation
- Examples - Usage patterns
- Architecture - Implementation details and complexity analysis
- Installation - Setup instructions for all platforms
Examples
Team Skills
team = tagmap.TagMap({
"alice": ["python", "typescript", "backend"],
"bob": ["cpp", "rust", "backend"],
"carol": ["ux", "ui", "design"],
})
team.query("python") # ['alice']
team.query("backend") # ['alice', 'bob']
team.query("python", "backend") # ['alice']
See EXAMPLES.md for additional usage patterns.
Performance
Tag operations (add, remove, check): O(1) average case AND queries (all tags): O(k·m) where k = result size, m = avg tags per key OR queries (any tag): O(n) where n = sum of keys matching each tag
See ARCHITECTURE.md for detailed complexity analysis and benchmarks.
Building from Source
Clone and build:
git clone https://github.com/originalsouth/tagmap.py.git
cd tagmap.py
python -m venv venv
source venv/bin/activate
pip install pybind11 pytest
pip install -e .
Run tests:
pytest test_tagmap.py -v
Requirements: Python 3.8+, C++20 compiler, pybind11. Build uses -Ofast -march=native optimizations.
For detailed build instructions, see INSTALLATION.md.
License
MIT License. See LICENSE for details.
Repository
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tagmap-0.1.18.tar.gz.
File metadata
- Download URL: tagmap-0.1.18.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecb51fbac32035b5f27ea53297625c3f3f80284867d2ba7c6942da4aae4d6849
|
|
| MD5 |
67f78ad0670ebdc159b0fa7482babbef
|
|
| BLAKE2b-256 |
3d6b9c80d62cf3813d9e416fad01abc8a7fc49dfd36ce2bbb9e6a793ef179578
|
File details
Details for the file tagmap-0.1.18-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: tagmap-0.1.18-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 128.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
943428bf8de5da36b36f92a4883be72ceec4416c37dab60d559901041c417312
|
|
| MD5 |
f5f03a4e09a42ef3c34360e72bc57c35
|
|
| BLAKE2b-256 |
07fc0e0453d2ecb9ceb631b0765f96f7564cf119228e4114b4ee3dfbc5620597
|
File details
Details for the file tagmap-0.1.18-cp311-cp311-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: tagmap-0.1.18-cp311-cp311-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.11, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd82df832aa91e83c4b32ee6b4ec3716fa2583341285ab106b09da911c5fb40b
|
|
| MD5 |
42c15fa86235997ea78a19f20ef80f50
|
|
| BLAKE2b-256 |
cbeecf8719f86ce456df8d422a69804ab21aaa7c475b55cbdec6dde6b01c0a7e
|
File details
Details for the file tagmap-0.1.18-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: tagmap-0.1.18-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 287.8 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d8296ef5d3b56cd838ffe05f0b47c6ceda18bf78ec25fb7eb630f5ba45c0dfd
|
|
| MD5 |
180da2f3f9039088c1b6baf1db8b81e3
|
|
| BLAKE2b-256 |
d3740a8d876ba5afe6bb976b85823c9416a38de76a4bc0281bc610cb9fc0ccac
|