Taxonomic types, projections and async taxonomy services for Polli-Labs.
Project description
Typus
Shared taxonomy & geo‑temporal types for the Polli‑Labs ecological stack
Typus centralises every domain object that the rest of our platform —
linnaeus, pollinalysis‑server, dashboards — needs: taxon records, clades,
hierarchical classification results, projection helpers and async database
services. Anything that speaks taxonomy imports Typus and stays DRY.
Features
- Wide ancestry view –
expanded_taxaORM exposes each rank (L10‑L70) on a single row for constant‑time lineage queries. - Async services –
PostgresTaxonomyService(ltree‑based) andSQLiteTaxonomyService(fixture) share an abstract interface. - Pydantic v2 models –
Taxon,Clade,HierarchicalClassificationResult, all JSON‑Schema‑exportable. - Projection utils – lat/lon ↔ unit‑sphere, cyclical time features, multi‑scale elevation sinusoids.
- Optional drivers only when you need them – install
*[postgres]or*[sqlite]extras; core install stays lightweight.
Requirements
- Python ≥ 3.10
Installation
Core (no DB drivers)
pip install typus
With Postgres backend
pip install "typus[postgres]" # adds asyncpg
With SQLite only (CI, offline, Codex sandboxes)
pip install "typus[sqlite]"
Development / tests / lint
pip install -e ".[dev,sqlite]" # pytest, pytest-asyncio, ruff, pre-commit, aiosqlite
Using uv:
uv pip install -e ".[dev,sqlite]"
Quick start
from typus import PostgresTaxonomyService, latlon_to_unit_sphere, RankLevel
svc = PostgresTaxonomyService("postgresql+asyncpg://user:pw@host/db")
bee = await svc.get_taxon(630955) # Anthophila
print(bee.scientific_name, bee.rank_level) # Anthophila RankLevel.L32
print(latlon_to_unit_sphere(31.5, -110.4)) # → x,y,z on S²
Offline mode (fixture)
from typus.services import SQLiteTaxonomyService
svc = SQLiteTaxonomyService() # uses tests/fixture_typus.sqlite
Using the SQLite fixture
The SQLite service uses a pre-built fixture database (tests/fixture_typus.sqlite) containing sample taxonomic data. This enables fully offline testing and development without requiring a PostgreSQL connection.
The fixture includes rich sample data with complete ancestry chains and parent relationships. To regenerate the fixture from the TSV source files, run:
python scripts/gen_fixture_sqlite.py
Developer guide
-
Lint & tests (single command):
ruff check . && ruff format . && pytest -q
-
Auto-format all files:
ruff format . # formats both typus/ and tests/
-
JSON Schemas:
python -m typus.export_schemas→typus/schemas/. -
SQLite fixture:
python scripts/gen_fixture_sqlite.pyregeneratestests/fixture_typus.sqlitefrom the TSV snippets. -
Pre‑commit: install hooks with
pre‑commit install.
Publishing (maintainers)
See polli‑labs/build/typus_publish.md for tag → TestPyPI → PyPI workflow.
License
MIT © 2025 Polli Labs
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 Distributions
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 polli_typus-0.1.6-py3-none-any.whl.
File metadata
- Download URL: polli_typus-0.1.6-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9edd4ce031e14676a561b74743bf979154d801031df407235a9f1c39bf4938c7
|
|
| MD5 |
910348035c6104ce26fc8cac47415a1e
|
|
| BLAKE2b-256 |
5865e158604a6b6ef86676e3f717b85f1345bd430fceff9b83d58ebbc2fbd1d6
|