Skip to main content

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

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

tagmap-0.1.17.tar.gz (12.3 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.17-cp311-cp311-win_amd64.whl (124.3 kB view details)

Uploaded CPython 3.11Windows x86-64

tagmap-0.1.17-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.17-cp311-cp311-macosx_10_9_universal2.whl (273.3 kB view details)

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

File details

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

File metadata

  • Download URL: tagmap-0.1.17.tar.gz
  • Upload date:
  • Size: 12.3 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.17.tar.gz
Algorithm Hash digest
SHA256 f19b0373f661328447b6852c21eff053b4255ddd189cf4d7db2544ad6beee6f6
MD5 7db597115e074d8a50215dcbd4a525b4
BLAKE2b-256 93960798c59635334db7d68c3d6124056c6062b8e7f3ee8a274036ce129552ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tagmap-0.1.17-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 124.3 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.17-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 975b12083fc2de6c4ed8957dacc80a67fa6aae5be00c4ccf133471c63060d16f
MD5 85aac519efbd315920336068ffbc8bda
BLAKE2b-256 64e054ce83d12a3517db7cc577a9e66cf085783767edd018358d30ce0501d1a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tagmap-0.1.17-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c45e7eff73bac8629b1e71fe0c858424b48ae43c00487e03326158035577bef3
MD5 d68a9552d72d5512a8ce485e35af80b0
BLAKE2b-256 b0801754eb03dcbc697d74dcdb95b0d74a19b2e70fa8283d56b7ff51694c149a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tagmap-0.1.17-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0cc4d922e91fe1e1cf1dc78ecbc1a86ec8bb76ec3fbf581e221146326897f983
MD5 6dc5a196def7fd3418f6d84c44df4092
BLAKE2b-256 1f929748d04577b3eb4e56dcbdbb67ee6cd8e9f869fbf0160e4fc0c38c6702f7

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