Skip to main content

Balarama

Balarama is a local in-memory hybrid analytical index for Python.

The core idea is simple:

  • keep rows as the source of truth
  • build sorted per-column access paths
  • load data once
  • run many repeated local queries and analytics very quickly

The primary use case now is a code corpus slice explorer for AI-assisted software development. You load function metadata once, then repeatedly filter by language, repo, split, code_len_chars, doc_len_chars, code_line_count, and similar fields for corpus prep, eval slicing, and prompt/example selection.

What Works Today

The implemented path is centered on the original hybrid design:

  • native C table engine with one row store and one sorted index array per column
  • bulk-friendly load-once path that appends rows first and builds indexes once
  • Python HybridTable API for equality/range filtering, counts, sums, row reconstruction, and value counts
  • higher-level CodeCorpusExplorer API for the CodeSearchNet metadata workflow
  • sample code corpus demo that runs locally from the repo
  • public CodeSearchNet metadata benchmark path with DuckDB as the first external local comparator

The earlier vector-search path is still in the repo as an experiment, but it is no longer the main product story.

Quick Example

from pathlib import Path

import balarama as br

csv_path = Path("examples/data/code_corpus_sample.csv")
explorer = br.CodeCorpusExplorer.from_csv(csv_path)

python_tests = explorer.examples(
    language="python",
    split="test",
    has_docstring=True,
    limit=3,
)

docstring_rich_train_chars = explorer.sum_code_length(
    language="python",
    split="train",
    has_docstring=True,
    min_doc_len=40,
)

top_repos = explorer.top_repos(
    has_docstring=True,
    min_doc_len=20,
    top_n=5,
)

Run It

Install the editable package into a virtualenv:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e .

For a standard release install after PyPI publish:

python -m pip install balarama

Run the code corpus sample app:

make demo-code-corpus

Run the full test suite:

make test

Run the public CodeSearchNet metadata benchmark:

make benchmark-codesearchnet-hybrid

The benchmark prepares a public CodeSearchNet metadata CSV, loads it into Balarama’s hybrid table engine, and compares repeated slice/count/sum/example/top-repo workloads against DuckDB on the same corpus.

Why This Direction

The strongest product story here is not “another database” and not “another vector store”.

It is:

  • load a large structured dataset once
  • keep it in memory
  • slice it repeatedly with indexed filters
  • reconstruct rows quickly
  • do this locally from Python without running a service

That is a better match for the original architecture and for real engineering workflows around dataset prep, eval slicing, and example selection.

Current Strengths We Intend To Preserve

  • contiguous in-memory data structures
  • explicit ownership and predictable behavior
  • sorted per-column access paths
  • stable rowid bridging rows and indexes
  • benchmarkability
  • small, understandable APIs

Non-Goals For The Main Product Story

  • no hosted service
  • no distributed clustering
  • no mutable operational database story
  • no ANN-first or vector-first product identity
  • no broad SQL engine ambitions

Repository Guide

Experimental vector-path docs remain available here:

Metadata

Release files for balarama 0.1.0

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

Built distribution (wheel)

Table of built distributions (wheels) for balarama 0.1.0
File Interpreter ABI Platform
balarama-0.1.0-cp311-cp311-macosx_13_0_arm64.whl CPython 3.11 CPython 3.11 macOS 13.0+ ARM64 Details

Release files / balarama-0.1.0-cp311-cp311-macosx_13_0_arm64.whl

Download URL balarama-0.1.0-cp311-cp311-macosx_13_0_arm64.whl
Size 37.8 kB
Tags CPython 3.11 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
019de539ee3826bb9f70b2240870d055db9a612a76deee21f4be35971dfa90fd
BLAKE2b-256 checksum
How to use checksums
a14fe093dc3823c34bc1ea176be1a3288788ea08c4320626c8c0c3f25ee600ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Security for balarama 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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