pyhdtkit
A pure-Python package to convert between RDF Turtle (.ttl) and HDT (.hdt):
.ttl→.hdt.hdt→.ttl- combine two or more
.hdtfiles into one
No CLI — import pyhdtkit is the interface. No Rust, no native extension.
Install (dev)
pip install -e ".[dev]"
Usage
from pyhdtkit import ttl2hdt, hdt2ttl, hdtcat
ttl2hdt("graph.ttl", "graph.hdt")
hdt2ttl("graph.hdt", "graph.ttl")
hdtcat(["a.hdt", "b.hdt"], "combined.hdt")
Errors
All three functions raise ValueError for anything that goes wrong — a
missing or unreadable input file, malformed Turtle, a truncated or corrupt
.hdt file, or an unwritable output path. hdtcat additionally requires
at least 2 input paths.
Status
All three functions are implemented: a real HDT binary reader and writer
(dictionary front-coding, BitmapTriples), built from scratch — no Rust, no
C extension, no wrapping an existing HDT library. rdflib handles Turtle
parsing/serialization; everything HDT-specific is pure Python.
The read path (hdt2ttl) is verified against a real .hdt file produced
by independent hdt-cpp tooling (tests/fixtures/snikmeta.hdt), not just
against our own writer.
Performance
HDT's compactness comes from succinct bit-level structures (rank/select
bitmaps, front-coded dictionaries) that are naturally suited to compiled
languages. This is pure Python — it will be slower and more memory-hungry
than the reference C++ (hdt-cpp) or a Rust implementation, especially at
large triple counts. That's an accepted, deliberate trade-off for this
package: correctness and hackability over raw speed.
Measured on this machine (benchmarks/bench.py, synthetic triples,
default front-coding block size):
| Triples | Write | Read | File size |
|---|---|---|---|
| 1,000 | 0.01s | 0.00s | 0.01 MB |
| 10,000 | 0.06s | 0.03s | 0.07 MB |
| 100,000 | 0.70s | 0.34s | 0.79 MB |
| 1,000,000 | 8.4s | 3.5s | 8.4 MB |
Roughly linear scaling. The bit-packing routines were rewritten early on to
avoid an O(n²) trap (repeatedly shifting one big Python integer instead of
streaming through a small bit buffer) — see binio.py's
pack_lsb_bitfields/unpack_lsb_bitfields — which is what makes the
numbers above hold up past a few thousand triples. No numpy or other
compiled-array dependency was needed to get here; one may get added later
if profiling on a real workload shows it's worth the extra dependency
weight.
Metadata
Release files for pyhdtkit 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyhdtkit-0.2.0.tar.gz | 23.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyhdtkit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.3 kB
Release files / pyhdtkit-0.2.0.tar.gz
| Download URL | pyhdtkit-0.2.0.tar.gz |
|---|---|
| Size | 23.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
793d0b3b8bf6d8b0b4f1f3feb1dfaef0850678f61db7915d7dfbbccc91397d69
|
|
BLAKE2b-256 checksum How to use checksums |
9b54e47a16ce61810cb96d43624f85fa09701703a895cd8e4c0db60435b4b8b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pyhdtkit-0.2.0-py3-none-any.whl
| Download URL | pyhdtkit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01992a11776b8a65290986015bbbbf75ffbd8486bcbe4cfa2e0bf48d83b271f1
|
|
BLAKE2b-256 checksum How to use checksums |
e68825b58c2ea0866bb7d9de262e5faf49d6266a6d6485aa097de57dc63a130e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|