Thank you for your interest in contributing to the SochDB Python SDK! This guide provides all the information you need to build, test, and contribute to the project.
- Development Setup
- Building from Source
- Running Tests
- Server Setup for Development
- Code Style
- Pull Request Process
- Architecture Overview
- Migration Guide
- Python 3.8+
- Rust toolchain (for building from source)
- Git
# Clone the repository
git clone https://github.com/sochdb/sochdb-python-sdk.git
cd sochdb-python-sdk
# Install in editable mode
pip install -e .
# Install development dependencies
pip install -e ".[dev]"cd sochdb-python-sdk
pip install -e .If you need to rebuild the native library:
# Build Rust library
cd sochdb
cargo build --release -p sochdb-storage
# Copy to Python SDK
cp target/release/libsochdb_storage.dylib \
sochdb-python-sdk/src/sochdb/_bin/darwin-arm64/
# For Linux
cp target/release/libsochdb_storage.so \
sochdb-python-sdk/src/sochdb/_bin/linux-x86_64/# Run Python tests
cd sochdb-python-sdk
pytest tests/
# Run with coverage
pytest --cov=sochdb tests/# Start SochDB server first
cd sochdb
cargo run -p sochdb-grpc
# In another terminal, run integration tests
cd sochdb-python-sdk
pytest tests/integration/# Test all examples
cd sochdb-python-sdk
./run_examples.sh
# Test specific example
python3 examples/25_temporal_graph_embedded.py# Development mode
cd sochdb
cargo run -p sochdb-grpc
# Production mode (optimized)
cargo build --release -p sochdb-grpc
./target/release/sochdb-grpc --host 0.0.0.0 --port 50051The server runs all business logic including:
- ✅ HNSW vector indexing (15x faster than ChromaDB)
- ✅ SQL query parsing and execution
- ✅ Graph traversal algorithms
- ✅ Policy evaluation
- ✅ Multi-tenant namespace isolation
- ✅ Collection management
Create sochdb-server-config.toml:
[server]
host = "0.0.0.0"
port = 50051
[storage]
data_dir = "./data"
[logging]
level = "info"We follow PEP 8 with some modifications:
# Format code
black src/ tests/
# Check types
mypy src/
# Lint
ruff check src/ tests/Follow conventional commits:
feat: Add temporal graph support
fix: Handle connection timeout
docs: Update API reference
test: Add integration tests for graphs
- All tests pass
- Code follows style guidelines
- Documentation updated
- Examples added/updated if needed
- No breaking changes (or documented in CHANGELOG)
-
Fork and Clone
git clone https://github.com/YOUR_USERNAME/sochdb-python-sdk.git cd sochdb-python-sdk -
Create Feature Branch
git checkout -b feature/your-feature-name
-
Make Changes
- Write code
- Add tests
- Update documentation
-
Test Locally
pytest tests/ black src/ ruff check src/
-
Commit and Push
git add . git commit -m "feat: Your feature description" git push origin feature/your-feature-name
-
Create Pull Request
- Go to GitHub
- Create PR from your branch
- Fill out PR template
- Wait for review
┌──────────────────────────────────────────────────────────┐
│ PYTHON SDK ARCHITECTURE │
├──────────────────────────────────────────────────────────┤
│ │
│ 1. EMBEDDED MODE 2. SERVER MODE │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Database │ │ SochDBClient │ │
│ │ (FFI bindings) │ │ (gRPC client) │ │
│ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │
│ ▼ ▼ │
│ libsochdb_storage.dylib sochdb-grpc server │
│ (Rust native library) (Rust gRPC service) │
└──────────────────────────────────────────────────────────┘
database.py (1,974 lines)
Databaseclass with FFI bindings- Key-value operations
- Temporal graph operations
- Namespace management
- Collection management
grpc_client.py (630 lines)
SochDBClientclass for gRPC- All server-based operations
- Connection management
- Error handling
format.py (162 lines)
WireFormatenum (TOON, JSON, Columnar)ContextFormatenum (TOON, JSON, Markdown)FormatCapabilitiesutilities
| Feature | Old (Fat Client) | New (Dual-Mode) |
|---|---|---|
| SDK Size | 15,872 LOC | 5,400 LOC (-66%) |
| Business Logic | In SDK (Python) | In Server (Rust) |
| Deployment | Single mode only | Embedded + Server |
| Bug Fixes | Per language | Once in server |
| Semantic Drift | High risk | Zero risk |
| Performance | FFI only | FFI + gRPC |
| Maintenance | 3x effort | 1x effort |
No breaking changes! We added embedded FFI support while keeping server mode.
New in 0.3.4:
# NEW: Temporal graphs in embedded mode
from sochdb import Database
db = Database.open("./mydb")
db.add_temporal_edge(...)
db.query_temporal_graph(...)
# NEW: Same temporal graph API in server mode
from sochdb import SochDBClient
client = SochDBClient("localhost:50051")
client.add_temporal_edge(...)
client.query_temporal_graph(...)Old Code:
from sochdb import Database, GraphOverlay
db = Database.open("./data")
graph = GraphOverlay(db)
graph.add_node("alice", "person", {"name": "Alice"})New Code (Server Mode):
from sochdb import SochDBClient
# Start server first: cargo run -p sochdb-grpc
client = SochDBClient("localhost:50051")
client.add_node("alice", "person", {"name": "Alice"})New Code (Embedded Mode):
from sochdb import Database
db = Database.open("./data")
# GraphOverlay is now built into Database
db.add_node("alice", "person", {"name": "Alice"})Key Changes:
GraphOverlayremoved - features merged intoDatabaseandSochDBClient- Server mode requires running
sochdb-grpcserver - Embedded mode uses direct FFI bindings (faster, no network)
- Same API for both modes
# Update version in setup.py
vim setup.py
# Update version in __init__.py
vim src/sochdb/__init__.py
# Update CHANGELOG.md
vim CHANGELOG.md# Build wheel
python3 setup.py bdist_wheel
# Check distribution
twine check dist/*# Test PyPI first
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# Production PyPI
twine upload dist/*Before submitting a PR, ensure:
- All unit tests pass:
pytest tests/unit/ - All integration tests pass:
pytest tests/integration/ - All examples run:
./run_examples.sh - Code formatted:
black src/ - Linting passes:
ruff check src/ - Type checking passes:
mypy src/ - Documentation updated
- CHANGELOG.md updated
- Main Repo: https://github.com/sochdb/sochdb
- Python SDK Issues: https://github.com/sochdb/sochdb-python-sdk/issues
- Discussions: https://github.com/sochdb/sochdb/discussions
- Contributing Guide: See main repo CONTRIBUTING.md
By contributing to SochDB Python SDK, you agree that your contributions will be licensed under the Apache License 2.0.