Skip to main content

Fast data structure for managing tags and metadata with efficient queries

Project description

TagMap

A fast, efficient data structure for managing tags and metadata in Python, built with C++ and pybind11.

Overview

TagMap is a specialized dictionary-like data structure optimized for managing multiple tags per key. It supports efficient queries for keys with specific tag combinations.

Features

  • ⚡ Fast tag-based queries with intersection (all-of) and union (any-of) operations
  • 📦 Efficient tag addition and removal
  • 🔍 Multiple query methods for flexible data retrieval
  • ⚙️ Built on high-performance C++ implementation
  • 📊 Perfect for metadata management, feature flags, and classification systems

Quick Start

Installation

pip install tagmap

Or with uv:

uv pip install tagmap

Basic Usage

import tagmap

# Create a TagMap
m = tagmap.TagMap()

# Add entries with tags
m["alice"] = {"dev", "python"}
m["bob"] = {"dev", "cpp"}
m["carol"] = ["design", "python"]

# Query all entries with both "dev" and "python"
results = m.query("dev", "python")
# Result: ['alice']

# Query entries with either "python" OR "ops"
results = m.query_any("python", "ops")
# Result: ['alice', 'carol']

# Check if an entry has a tag
has_tag = m.has_tag("alice", "python")
# Result: True

# Add/remove tags
m.add_tag("alice", "ml")
m.remove_tag("bob", "dev")

Documentation

Common Use Cases

Team Skills Management

team = tagmap.TagMap({
    "alice": ["python", "typescript", "backend"],
    "bob": ["cpp", "rust", "backend"],
    "carol": ["ux", "ui", "design"],
})

# Find all Python developers
python_devs = team.query("python")

# Find all backend developers
backend_devs = team.query("backend")

# Find people with backend + Python skills
full_stack = team.query("python", "backend")

Content Classification

articles = tagmap.TagMap({
    "post_1": ["python", "tutorial", "beginner"],
    "post_2": ["python", "advanced"],
    "post_3": ["javascript", "tutorial"],
})

# Find beginner Python tutorials
beginners = articles.query("python", "tutorial", "beginner")

# Find tutorials for learning (any level)
tutorials = articles.query_any("tutorial")

Feature Deployment Tracking

features = tagmap.TagMap({
    "auth_v2": ["production", "staging"],
    "new_dashboard": ["staging", "beta"],
    "payment": ["production"],
})

# What's in production?
prod = features.query("production")

# What's available for testing?
testing = features.query_any("staging", "beta")

# How many features are in both staging and beta?
count = features.count(["staging", "beta"])

Performance

TagMap is designed for high-performance queries on tagged data:

  • Query operations: O(n) where n is the number of results
  • Tag operations: O(1) average time for add/remove/check
  • Memory efficient: Optimized inverted index for fast queries
  • Scales well: Handles thousands of entries with hundreds of tags

See ARCHITECTURE.md for detailed performance characteristics.

Building from Source

For development or to use the latest features:

# Clone the repository
git clone https://github.com/originalsouth/tagmap.py.git
cd tagmap.py

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install pybind11 pytest

# Build and install
pip install -e .

# Or use the Makefile
make

# Run tests
pytest test_tagmap.py -v

Requires:

  • Python 3.8+
  • C++20 compatible compiler
  • pybind11

Build Methods

Both pip install -e . and make use identical compiler optimizations:

  • Optimization: -Ofast (aggressive speed optimization)
  • CPU-specific: -march=native (optimize for your CPU)
  • Link-time optimization: -flto=auto
  • Result: Equivalent performance from both methods

See INSTALLATION.md for platform-specific build instructions.

Examples

Check EXAMPLES.md for comprehensive examples including:

  • Team member skills tracking
  • Blog post categorization
  • Feature deployment tracking
  • Document classification
  • Dynamic tag management
  • Bulk operations
  • Analytics and reporting

Contributing

We welcome contributions! Please see CONTRIBUTING.md for:

  • Development setup
  • Code style guidelines
  • Testing requirements
  • Pull request process
  • Reporting issues

License

TagMap is licensed under the MIT License. See LICENSE file for details.

Authors

  • originalsouth - Initial implementation

Changelog

See GitHub Releases for version history and release notes.

Support

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

tagmap-0.1.15.tar.gz (14.2 kB view details)

Uploaded Source

Built Distributions

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

tagmap-0.1.15-cp311-cp311-win_amd64.whl (126.0 kB view details)

Uploaded CPython 3.11Windows x86-64

tagmap-0.1.15-cp311-cp311-manylinux_2_39_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

tagmap-0.1.15-cp311-cp311-macosx_10_9_universal2.whl (276.2 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file tagmap-0.1.15.tar.gz.

File metadata

  • Download URL: tagmap-0.1.15.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tagmap-0.1.15.tar.gz
Algorithm Hash digest
SHA256 dadf073028c03fccd819fd28276399b32bea7b1aaab4c96500bd9fe64d8be4f9
MD5 dd4f9b4bed9aedeb214176c0cff153e9
BLAKE2b-256 71042669759d636956af24980cfb90a48651ef47a5412c29210bc845ec6b4ba3

See more details on using hashes here.

File details

Details for the file tagmap-0.1.15-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: tagmap-0.1.15-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 126.0 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

Hashes for tagmap-0.1.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fce8a5dd13980ff5dff7db6e54a37e8ce66f95ebb1b5221b0459274d3c43ce04
MD5 d0fb498086c946bf98d52b7739a4de28
BLAKE2b-256 c92f328cd6b25a9afeed5329436f2d4d15f775fe695c1a0aaff6b7a6dd17b3b0

See more details on using hashes here.

File details

Details for the file tagmap-0.1.15-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for tagmap-0.1.15-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 f9fbb9557642fe3ff5c1e20f2114e08ef40c03eef3e1f7d397242b2eed1e3862
MD5 168d7c207aceb6707b58b988ca4a630b
BLAKE2b-256 5a0d8168d3fdb41c777ae4809743dc4da3ff354d5f10275ff8ab3143e18a68e4

See more details on using hashes here.

File details

Details for the file tagmap-0.1.15-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for tagmap-0.1.15-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f7afbc2007d7172d1a2707822212a7a906d549b0857b1ff68fc6569800c0595a
MD5 9928a93fd067d31e04e7b0acae4fe953
BLAKE2b-256 3369f78cc14710fd5e09430547d3db7e09617df1e13d22e277faba8d375e44ee

See more details on using hashes here.

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