Skip to main content

kvgit 🔀

Git-style versioning for your data. Commits, branches, and merges -- backed by a dict-like MutableMapping.

Features Description
Dict interface MutableMapping[str, Any] -- reads and writes work like a dict
Commits Immutable, content-addressable snapshots with rollback
Branches Cheap forks with CAS-based optimistic concurrency
Tags Immutable names for commits; a tagged commit outlives every branch that reached it, in every kvgit version
Three-way merge Auto-merges non-overlapping changes; pluggable merge fns for conflicts
Pluggable backends In-memory, disk (SQLite), PostgreSQL, or bring your own KVStore -- any store with an atomic conditional batch
Concurrent GC Garbage collection runs beside live writers, from any process sharing the store
Content-addressed storage Equal values are stored once across keys, commits, and branches
Chunked codecs Optional dedup inside large numpy arrays and pandas DataFrames -- equal buffers (slices included) stored once

Install

pip install kvgit              # in-memory and disk (SQLite)
pip install kvgit[postgres]    # adds PostgreSQL backend via psycopg
pip install kvgit[scientific]  # adds chunked codecs for numpy / pandas

Quick example

import kvgit

main = kvgit.open()  # a Worktree on branch "main" of an in-memory Repo
repo = main.repo

main["user"] = "alice"
main["score"] = 0
main.commit()

# Branch and diverge
repo.branches.create("dev", at=main.head)
dev = repo.worktree("dev")
dev["score"] = 999
dev.commit()

print(main["score"])  # 0   (main unchanged)
print(dev["score"])   # 999 (dev branch)

# Tag a commit by name -- immutable, and safe from garbage collection
repo.tags.create("v1", main.head)
print(repo.snapshot(tag="v1")["score"])  # 0

A Repo owns the backend and everything store-wide: branches, tags, history, snapshots, garbage collection. repo.branches and repo.tags are live mappings of name to commit, with create and delete, shaped like pygit2's repo.branches. A Worktree is one branch checked out for work -- a dict whose writes stay pending until commit(). A Snapshot is a read-only dict pinned to one commit.

from kvgit import Repo
from kvgit.kv.disk import Disk

with Repo(Disk("/tmp/kvgit-demo")) as on_disk:
    wt = on_disk.worktree("main", create=True)  # open, or create at the empty root
    wt["k"] = "v"
    print(wt.status())  # Status(updated=frozenset({'k'}), removed=frozenset())
    wt.commit(info={"msg": "first"})
    for c in on_disk.log(branch="main"):
        print(c.hash[:8], c.info)  # the commit, then the empty root commit

For git users

git kvgit
git worktree add / git checkout s1 repo.worktree("s1")
edit, git add wt[k] = v -- no index; everything is pending until commit
git status wt.status()
git commit [paths] wt.commit([keys=...])
git restore . wt.discard()
git reset --hard c wt.reset(c)
git merge x wt.merge(branch="x")
git cherry-pick c / git revert c wt.cherry_pick(c) / wt.revert(c)
git branch, git tag (list) list(repo.branches), dict(repo.tags)
git branch [-D] x repo.branches.create("x") / repo.branches.delete("x")
git tag [-d] v1 repo.tags.create("v1", c) / repo.tags.delete("v1")
git log, git show c, git diff a b, git merge-base a b repo.log(...), repo.get_commit(c), repo.diff(a, b), repo.merge_base(a, b)
git show v1:path repo.snapshot(tag="v1")[key]
git gc [--prune=now] repo.gc([min_age=0])

Where it differs: there is no index; several worktrees can hold one branch, and their commits race and merge rather than being refused (commit(on_moved="raise") refuses instead, raising BranchMovedError, for data whose keys aren't independent); a conflicted merge raises MergeConflict and changes nothing (unless a merge function such as text_merge writes markers into the value); commit hashes are not git's, and there are no remotes.

Merging

Worktree.merge() merges a branch, tag or commit into the worktree's branch: lowest common ancestor, three-way resolve, and a two-parent merge commit guarded on your own head. As in git, a branch that has not moved since the fork fast-forwards instead, and fast_forward=False writes the merge commit anyway:

dev["score"] = 500
dev.commit()

result = main.merge(branch="dev")  # truthy when merged
print(result.strategy)  # "fast_forward": main hadn't moved since dev forked
print(main["score"])    # 500

Overlapping changes need a merge function per key, or a default_merge fallback. text_merge() resolves line-oriented text with git-style <<<<<<< markers (its ours_label / theirs_label arguments name them); anything it cannot mark -- binary, non-UTF-8, oversized -- raises CantMark, filed as an ordinary conflict:

from kvgit import text_merge

main["notes"] = "alpha\nbeta\n"
main.commit()

repo.branches.create("edits", at=main.head)
edits = repo.worktree("edits")
edits["notes"] = "alpha\nBETA\n"
edits.commit()

main["notes"] = "ALPHA\nbeta\n"
main.commit()

main.merge(branch="edits", default_merge=text_merge())
print(main["notes"])  # "ALPHA\nBETA\n" -- both edits kept

Merge functions see decoded values, so text_merge() works on str values under the default codec. kvgit.merges.text is the same merge over raw bytes, for keys whose values already are bytes.

Registrations resolve most-specific-first: a key takes its exact-key registration, else the longest registered prefix it starts with, else default_merge. Prefixes cover keys whose names are not known when the policy is set:

from kvgit import MergeChoice, text_merge

main.set_merge_prefix("runs/", MergeChoice.OURS)   # this branch owns runs/
main.set_merge_fn("runs/index", text_merge())      # except this one key

Rules can live on the Repo too -- Repo(backend, merge_fns=..., merge_prefixes=..., default_merge=...) -- for every worktree it opens. A worktree's own registrations layer over the repo's, and a call's merge_fns= / merge_prefixes= / default_merge= over both.

A registration holds either a merge function or a MergeChoice, and the two reach differently:

  • A merge function is consulted only where both sides changed a key. A change only one side made is applied as it always was.
  • A MergeChoice is a standing policy: it hands that side every key either side changed under it. So OURS also drops a key the other side added and keeps one the other side removed -- what a branch that owns a whole namespace needs. Nothing is read or decoded for those keys.

kvgit.merges.ours and kvgit.merges.theirs are the merge-function form, for keys where one side wins only when both sides collide. They keep that side's stored value as it stands rather than rewriting it, so the merge writes no new blob -- and if the chosen side removed the key, the merge removes it.

Keys both sides changed to the same bytes merge cleanly with no merge function, even though each side wrote its own copy.

A post_check(key, merged_bytes) predicate runs over every merge-produced value; returning False files that key as conflicted. on_conflict="abandon" leaves the branch untouched instead of raising. Merging refuses with ValueError while the worktree has pending changes -- commit or discard() first.

cherry_pick(c), revert(c) and the general apply(base, target) replay one change onto the worktree's branch as an ordinary single-parent commit, with the same merge options.

Codecs and trust

A repo's codec turns values into stored bytes. codec="pickle" is the default: it is what makes a worktree a dict of anything. But unpickling can execute code, so anyone who can write a pickle-codec store -- a shared Postgres table, a disk directory -- can run code in every process that reads it. For a store more than one party can write, use codec="bytes": kvgit then never decodes anything, values must be bytes, and you choose where (if anywhere) untrusted pickles are loaded. snapshot.raw reads the stored bytes under any codec.

The codec is fixed per store in practice: values written under one codec read back as their stored bytes under "bytes" and generally fail to decode under any other, so switching an existing store means rewriting its values.

Chunked codecs (numpy / pandas)

Large numpy arrays and pandas DataFrames -- and any sliced views of them -- can be stored once and shared across keys, commits, and branches:

import kvgit
import numpy as np

s = kvgit.open(codec="scientific")

big = np.arange(1_000_000, dtype="float64")  # ~8 MB
s["full"] = big
s["head"] = big[:100_000]
s["tail"] = big[-100_000:]
s.commit()
# All three keys reference the same chunk in the store -- ~8 MB total, not ~24 MB.

Pandas DataFrames piggyback on the numpy codec via their underlying block ndarrays. See docs/quick-start.md and the API reference.

Part of the agex stack

kvgit provides versioned agent memory in agex with branching and rollback. It also works as a versioned backing store for monkeyfs virtual filesystems -- pass a Worktree anywhere a dict is expected.

Development

From the repository root. The package is in python/ and its native extension in crates/py, so building it needs a Rust toolchain (rustup); uv rebuilds the extension when the Rust sources change.

uv sync --extra dev
uv run pytest

Documentation

See docs/ for detailed documentation:

  • Quick Start -- common patterns with runnable examples
  • API Reference -- full reference for all classes, methods, and types
  • Storage format -- every key kvgit writes, shared with the TypeScript package byte for byte

Metadata

Release files for kvgit 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kvgit 0.5.1
File Size Uploaded Provenance Actions
kvgit-0.5.1.tar.gz 344.0 kB With provenance Details for kvgit-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for kvgit 0.5.1
File Actions
kvgit-0.5.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for kvgit-0.5.1-cp310-abi3-win_amd64.whl
kvgit-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for kvgit-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
kvgit-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for kvgit-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
kvgit-0.5.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for kvgit-0.5.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
kvgit-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for kvgit-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
kvgit-0.5.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for kvgit-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
kvgit-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for kvgit-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 8.6 MB

Release files / kvgit-0.5.1.tar.gz

Download URL kvgit-0.5.1.tar.gz
Size 344.0 kB
Tags Source
SHA-256 checksum
How to use checksums
617a6fcf0a84b5c3c538558f9229d3ba263b5bac85adb711038e30a08ac9ad2d
BLAKE2b-256 checksum
How to use checksums
e53691ec8227fdbf2b9d7bb6a8b4655a4afc9b4103d8801364f225d08816e632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-win_amd64.whl

Download URL kvgit-0.5.1-cp310-abi3-win_amd64.whl
Size 1.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e0ff913edb2787da6df290b1704b2a9676d002d56cee3bbc34d8e9ede06721ec
BLAKE2b-256 checksum
How to use checksums
1127e082a2837afe4301e3fd0a7a95dba58c54353481dbc4fa6a4d58c3fb6a72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL kvgit-0.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
26f6e836507bc1d5a2b26be3fa3899d97ee17edcf48af0b55c9736e054cb20ed
BLAKE2b-256 checksum
How to use checksums
5d50339698c947d3eba37cd9e0de1d4afb487b05d55cf0e5db6a0954c3d75c10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL kvgit-0.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.3 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
d812f2d0e9e992da510a440d341bbb9c5e1e4cb5e37b8ff3f878439a130b56c5
BLAKE2b-256 checksum
How to use checksums
4a427e7e27df6ca274fa7d2c1d7eb4a540fccfacbc3aab2614cd76edc17735c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL kvgit-0.5.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
7dc19fffc474a689bbd44001867d8a75634a55ee7e5d831ff36dca022bafcbb8
BLAKE2b-256 checksum
How to use checksums
f8f77fa336c62c74b2809d637fe08a1dad57d2865253cd1588359abefdff6b39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL kvgit-0.5.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
d5b13797ff4f6046bdbfa8a88317052b175c6ce44e72019f06e0e540125ca5ca
BLAKE2b-256 checksum
How to use checksums
274053f3dab7b46597373bc06b96c674b0415f84d6eb29787ba53fed851d4a6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL kvgit-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c68c2213f1ba41e2203bac203477782c1fe413f39db67887e8bec68964272e53
BLAKE2b-256 checksum
How to use checksums
47e6e033fb9fee1a12bbe34f3a13e5d357c451d7a8fc2812c1a8a649f83d1cc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / kvgit-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL kvgit-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
177b6a0ff06c623590afd183a59a63e820ce26148e4af54c2492e2da62b15b99
BLAKE2b-256 checksum
How to use checksums
1346e82b47e706ce282a6955b8ed8e7a6b2a6cb53371641384839a0b1164d5c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for kvgit 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for kvgit-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page