Python SDK for Litebase Storage and Stream APIs
Project description
litebase
Litebase Python SDK provides a modern, lightweight client for accessing Litebase's Storage and Stream APIs. It is designed for developers who require scalable, versioned key-value storage, high-throughput event streams, and real-time subscription capabilities, all with a clean Python experience.
Installation
Install using uv for faster dependency management:
uv pip install litebase
or using pip:
pip install litebase
Litebase officially supports Python 3.8 and above.
Quickstart
Litebase is designed for simplicity. A few lines of code are enough to get started.
Storage API
from litebaseio import storage
# Initialize a storage namespace
store = storage("my-storage")
# Set a single key
set_response = store.set("user:1", b'{"name": "Alice", "email": "alice@example.com"}')
print(f"Set operation transaction ID: {set_response.tx}")
# Retrieve a single key
user_data = store.get("user:1")
print("Retrieved user data:", user_data)
# Batch write multiple records
batch_response = store.write([
{"key": "user:2", "value": {"name": "Bob", "email": "bob@example.com"}},
{"key": "user:3", "value": {"name": "Charlie", "email": "charlie@example.com"}},
])
print(f"Batch write transaction ID: {batch_response.tx}")
# Batch read multiple records
read_response = store.read(["user:2", "user:3"])
for record in read_response.data:
print(f"Key: {record.key}, Value: {record.value}")
# Check if a key exists
exists = store.head("user:1")
print("Key user:1 exists:", exists)
# Delete a key
delete_response = store.delete("user:1")
print(f"Deleted key user:1, transaction ID: {delete_response.tx}")
Stream API
from litebaseio import stream
# Push multiple events into a stream
push_response = stream.push([
{"stream": "sensor.temperature", "data": {"value": 22.5}},
{"stream": "sensor.temperature", "data": {"value": 23.1}},
])
print(f"Pushed {push_response.count} events to stream")
# List the most recent events from a stream
events = stream.list("sensor.temperature", limit=10)
for event in events:
print(f"Transaction ID: {event.tx}, Data: {event.data}, Time: {event.time}")
# Retrieve a specific event by transaction ID
if events:
tx_id = events[0].tx
event_data = stream.get("sensor.temperature", tx=tx_id)
print("Specific event data:", event_data)
# Subscribe to real-time events
print("Subscribing to real-time sensor.temperature updates:")
for event in stream.subscribe("sensor.temperature", start_tx=0):
print(f"Received event: {event.data}")
# Optionally break after first event for demo purposes
break
Before running any examples, ensure you have set your API key:
export LITE_API_KEY="your-litebase-api-key"
export LITE_BASE_URL="https://api.litebase.io" # Optional, defaults automatically
Development
Clone the repository:
git clone https://github.com/litebaseio/litebase-py.git
cd litebase-py
Set up the development environment:
make install-dev
make test
Testing is based on real API interactions with a Litebase server. A valid Litebase API key is required to run the full test suite successfully.
License
This project is licensed under the MIT License.
Litebase provides a reliable platform for structured and real-time data management, whether for analytics, IoT applications, mobile telemetry, or large-scale distributed systems. This SDK is intended to offer a minimal, efficient, and production-ready integration path for developers building modern applications.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litebaseio-0.0.4.tar.gz.
File metadata
- Download URL: litebaseio-0.0.4.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c9634c910d9e56556c79cccdbed6d4693adf93dce72226f712768db95601f58
|
|
| MD5 |
c035710dbe7c5f680b29406d23b64d8a
|
|
| BLAKE2b-256 |
513a4ff483d543c87c23e3434bbf0c43fe4cb9f29b9ccacd223f8d9488d983fd
|
File details
Details for the file litebaseio-0.0.4-py3-none-any.whl.
File metadata
- Download URL: litebaseio-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5329644555c2007c00a0ef6b8364917fa126d29795f060a9f54aec85513d6310
|
|
| MD5 |
018dfd49910fa027912e0d3f481541ce
|
|
| BLAKE2b-256 |
50ee6f0ec7607df087856216684896d18fbccacba78fce751ed464e0c08d4ddd
|