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.14.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.14-cp311-cp311-win_amd64.whl (126.0 kB view details)

Uploaded CPython 3.11Windows x86-64

tagmap-0.1.14-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.14-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.14.tar.gz.

File metadata

  • Download URL: tagmap-0.1.14.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.14.tar.gz
Algorithm Hash digest
SHA256 1745c9385ba29303cad2dc768adb3ed37916aec2832be9e75e7247a9f76dd25a
MD5 d5cf571d6a4fe508586472531e1e38be
BLAKE2b-256 0a30478002330b4012523d05e6ae9439655d8889662fc646d7c489a29da3e777

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tagmap-0.1.14-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.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 883b463ca28057725171c29966a6655e300889cfb154efb8f69635f22cd3f0c4
MD5 a260f08ecdac2de14c14c0de16086593
BLAKE2b-256 a977c8ef5d479dfd2d43f9bfdb0b4ebf7aba5641eb189565b0e47e1c5e2f2e84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tagmap-0.1.14-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c8511f74ebe9f8709796d343c9535f8bed8232357091e0601b204cbd36fba7aa
MD5 af20b3b1250b21e1e9c64b6a00ec2a7f
BLAKE2b-256 207c0ad8ce8612871717740a16983beccd277116ac6c8d64b59a10193679d942

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tagmap-0.1.14-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2dc72172c92a62915ec246e7ecda6d321d3ede0b4a6d997d42ae918bf81765bb
MD5 f9620a80aa8a71c3a2a18f086c62707d
BLAKE2b-256 1e3afb50c62d5353d1c35747dc3bcf91eef600bacb5c6ece6d42a88e82033402

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