Skip to main content

Add your description here

Project description

Bear Lake

A lightweight, file-based database built on Polars and Parquet, designed for fast analytics and easy data management.

Bear Lake provides a simple API for creating partitioned tables, inserting data, and running efficient queries using Polars' lazy evaluation. All data is stored as Parquet files with automatic partitioning support.

Usage

Quick Start

import polars as pl
import bear_lake as bl

# Connect to database
db = bl.connect("my_database")

# Create a table with schema and partitioning
schema = {
    "date": pl.Date,
    "ticker": pl.String,
    "price": pl.Float64
}

db.create(
    name="stocks",
    schema=schema,
    partition_keys=["ticker"],
    primary_keys=["date", "ticker"],
    mode="error"
)

# Insert data
data = pl.DataFrame({
    "date": ["2024-01-01", "2024-01-02"],
    "ticker": ["AAPL", "AAPL"],
    "price": [150.0, 152.5]
})

db.insert("stocks", data, mode="append")

# Query data using Polars lazy evaluation
result = db.query(
    bl.table("stocks")
    .filter(pl.col("ticker") == "AAPL")
    .select(["date", "price"])
)

print(result)

API Reference

Database Connection

db = bl.connect(path: str) -> Database

Connect to a database at the specified path. Creates the directory if it doesn't exist.

Creating Tables

db.create(
    name: str,
    schema: dict[str, pl.DataType],
    partition_keys: list[str],
    primary_keys: list[str],
    mode: str = "error"
)

Parameters:

  • name: Table name
  • schema: Dictionary mapping column names to Polars data types
  • partition_keys: Columns to partition data by (creates hierarchical folder structure)
  • primary_keys: Columns that form a unique identifier (used for deduplication)
  • mode: How to handle existing tables - "error" (default), "replace", or "skip"

Inserting Data

db.insert(name: str, data: pl.DataFrame, mode: str = "append")

Parameters:

  • name: Table name
  • data: Polars DataFrame to insert
  • mode: How to handle existing partitions - "append" (default), "overwrite", or "error"

Querying Data

result = db.query(expression: pl.LazyFrame) -> pl.DataFrame

Execute a lazy Polars query and return results. Use bl.table(name) to get a LazyFrame for a table.

# Get a LazyFrame for querying
lazy_df = bl.table("stocks")

# Build query with Polars operations
result = db.query(
    lazy_df
    .filter(pl.col("date") > "2024-01-01")
    .group_by("ticker")
    .agg(pl.col("price").mean())
)

Deleting Data

db.delete(name: str, expression: pl.Expr)

Delete rows matching the given expression from all partitions.

# Delete all rows where ticker is AAPL
db.delete("stocks", pl.col("ticker") == "AAPL")

Dropping Tables

db.drop(name: str)

Remove a table and all its data.

Table Metadata

# List all tables
tables = db.list_tables() -> list[str]

# Get table schema
schema = db.get_schema(name: str) -> dict[str, pl.DataType]

# Get partition keys
partition_keys = db.get_partition_keys(name: str) -> list[str]

# Get primary keys
primary_keys = db.get_primary_keys(name: str) -> list[str]

Optimizing Tables

db.optimize(name: str)

Deduplicate rows based on primary keys (keeping the last occurrence) and sort data. This compacts storage and improves query performance.

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

bear_lake-0.1.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bear_lake-0.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file bear_lake-0.1.2.tar.gz.

File metadata

  • Download URL: bear_lake-0.1.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bear_lake-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f2b47fed19de69ff858a43772b3a23532f201dbc3fe97d1bdf0b30fbf5ee9ddc
MD5 823151efacb2d7f460056a8a6553396a
BLAKE2b-256 e919b810ac5cee771888fb5051e7426ed0c8ad9e5b9df08a01fd3d0f33883ccf

See more details on using hashes here.

File details

Details for the file bear_lake-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bear_lake-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bear_lake-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c884d3d52a5f4eb5a9ef8a3055eb3fbef1f06ff4d8462421287b2b47dd31d119
MD5 7f75bda90e5599ed809ec0d6baa4c7fa
BLAKE2b-256 12013d618e750bbf19a4441910c8b3d7e24d16a4055b8de602257c58a64f0494

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