Core data model and persistence layer for tracking cannabis plants and strains.
Cannabase is a small, framework-agnostic Python library that provides:
- Strongly-typed models for strains and plants
- A clear separation between plant IDs and grower labels
- Support for clones, batches, rooms, and lifecycle stages (veg, flower, harvested, etc.)
- A simple service layer (
PlantService) that UI clients (Discord bots, CLIs, web apps) can talk to - A SQLite-backed repository implementation
- A pytest test suite with coverage configuration
It is intentionally minimal: a clean domain layer with persistence and tests.
From a checkout of this repo:
pip install -e ".[dev]"Or with Poetry:
poetry installStrains are defined with the Strain model in cannabase.models:
name– e.g. "Blue Dream"breeder– optional breeder or sourcegenetics– e.g. "Blueberry x Haze"flower_time_days_min/flower_time_days_maxstrain_type– indica, sativa, hybrid, or unknownnotes
Strains are keyed by an internal integer id and managed via StrainRepository and SQLiteStrainRepository.
Plants track lifecycle details with fields including:
strain_id,label,status,origin_typeroom,position,medium,container_size_liters- Lifecycle dates: planted, veg start, flower start, harvested, culled
- Yield (
wet_weight_g,dry_weight_g) and notes
Convenience properties:
age_daysdays_in_stageis_active
import datetime as dt
from cannabase.db import connect, init_schema
from cannabase.sqlite_repo import SQLitePlantRepository, SQLiteStrainRepository
from cannabase.services import PlantService
conn = connect("grow.db")
init_schema(conn)
strain_repo = SQLiteStrainRepository(conn)
plant_repo = SQLitePlantRepository(conn)
service = PlantService(strain_repo=strain_repo, plant_repo=plant_repo)
plant = service.add_plant(
strain_name="Blue Dream",
planted_at=dt.date(2025, 4, 20),
)
print(f"{plant.label} added! ID: {plant.id}")
plant = service.update_status(
plant_id=plant.id,
new_status="flower",
when=dt.date(2025, 5, 20),
)
print(plant.notes)pytest
coverage run -m pytest
coverage report
coverage htmlCoverage behavior is configured in pyproject.toml.
cannabase/
models.py
repositories.py
sqlite_repo.py
services.py
db.py
tests/
conftest.py
test_models.py
test_services.py
test_sqlite_repo.py
- Discord bot integration
- CLI (
python -m cannabase) - Additional query helpers
- Event logging for feed/water/pest-management