Skip to main content

TwitterBanner_SkyHyperpole2_1991

Typus

CI

Shared taxonomy & geo‑temporal types for the Polli‑Labs ecological stack

Documentation: https://docs.polli.ai/typus

Typus centralises every domain object that the rest of our platform — linnaeus, pollinalysis-server, dashboards … — needs: taxon records, clades, canonical classification results, projection helpers and async database services. Anything that speaks taxonomy imports Typus and stays DRY.


Features

  • Wide ancestry view – expanded_taxa ORM exposes each rank (L10 → L70) on a single row for constant‑time lineage queries.
  • Async services – PostgresTaxonomyService (ltree) & SQLiteTaxonomyService (fixture) share one interface.
  • Pydantic v2 models – Taxon, Clade, ClassificationResult, and one-release deprecated classification aliases, all JSON-Schema-exportable.
  • Classification decision helpers – Chow thresholds, hierarchy repair, and cost-sensitive expected-utility policies operate on calibrated ClassificationResult belief without retraining.
  • Taxonomy summaries & pollinator groups – TaxonSummary trails plus coarse PollinatorGroup helpers for UI labels.
  • Projection utils – lat/lon ↔ unit‑sphere, cyclical‑time features, multi‑scale elevation sinusoids.
  • Optional dependencies only when you need them – the core install is pydantic-only: DTOs, geometry, and typus.ops import without sqlalchemy or rapidfuzz. Add polli-typus[services] for the taxonomy/elevation services, [postgres] / [sqlite] for a driver, [fuzzy] for fuzzy rank inference, [loader] for TSV/HTTP ingest, or [all] for everything.
  • Offline SQLite loader – typus-load-sqlite CLI builds and caches the offline dataset

Requirements

  • Python ≥ 3.10

Installation

Core (pydantic only)

uv pip install polli-typus        # import typus

The core install depends on pydantic alone. Models, canonical geometry, typus.ops, projections, and the classification/decision helpers all import without sqlalchemy, rapidfuzz, or any DB driver.

Extras

Extra Adds Needed for
fuzzy rapidfuzz fuzzy (non-exact) infer_rank lookups
services sqlalchemy[asyncio] + [fuzzy] TaxonomyService, SQLiteTaxonomyService, PostgresTaxonomyService, ElevationService, typus.orm
postgres [services] + asyncpg Postgres taxonomy/elevation backends
sqlite [services] + aiosqlite offline SQLite backend (CI, sandboxes)
pgvector psycopg-binary pgvector helpers
loader polars/pandas/requests/tqdm typus-load-sqlite TSV/HTTP ingest
all [services,postgres,sqlite,pgvector] everything except loader/docs tooling
uv pip install "polli-typus[postgres]"    # services + asyncpg
uv pip install "polli-typus[sqlite]"      # services + aiosqlite
uv pip install "polli-typus[loader]"      # TSV/HTTP ingest tooling
uv pip install "polli-typus[all]"         # services + every driver

The service symbols re-exported from typus (TaxonomyService, SQLiteTaxonomyService, PostgresTaxonomyService, TaxonomyServiceError, BackendConnectionError, TaxonNotFoundError, ElevationService, PostgresRasterElevation) are resolved lazily on first attribute access, so a bare polli-typus install can still import typus. Accessing one without the extra raises a ModuleNotFoundError naming the extra to install. Note that from typus import * eagerly resolves all of them and therefore requires polli-typus[services].

Development / tests / lint

uv pip install -e ".[dev,loader]"   # [dev] pulls [all] plus pytest, ruff, ty, pre-commit …

Quick start

# Download or build the expanded taxonomy dataset locally (~475MB sqlite / ~440MB tsv.gz)
# The loader creates recommended indexes by default for fast name search
typus-load-sqlite --sqlite expanded_taxa.sqlite
from pathlib import Path
from typus.services import SQLiteTaxonomyService

svc = SQLiteTaxonomyService(Path("expanded_taxa.sqlite"))
bee = await svc.get_taxon(630955)           # Anthophila
print(bee.scientific_name, bee.rank_level)  # Anthophila RankLevel.L32
assert bee.source == "iNaturalist"          # authority of the numeric concept IDs

You can also load on-demand in code (will download if missing):

from pathlib import Path
from typus.services import load_expanded_taxa, SQLiteTaxonomyService

db_path = load_expanded_taxa(Path("expanded_taxa.sqlite"))  # create_indexes=True by default
svc = SQLiteTaxonomyService(db_path)

Name search (v0.4.0+)

# Scientific prefix match
taxa = await svc.search_taxa("Apis", scopes={"scientific"}, match="prefix")

# Vernacular (common name) exact
taxa = await svc.search_taxa("honey bee", scopes={"vernacular"}, match="exact")

Taxonomy summaries & pollinator groups (v0.4.2)

from pathlib import Path
from typus import PollinatorGroup
from typus.services import SQLiteTaxonomyService

svc = SQLiteTaxonomyService(Path("expanded_taxa.sqlite"))

# Compact trail for UIs
bee_summary = await svc.taxon_summary(630955)  # Anthophila
print(bee_summary.format_trail())  # Animalia → Arthropoda → Insecta → Hymenoptera → Apidae → Anthophila

# Coarse pollinator grouping
groups = await svc.pollinator_groups_for_taxon(47219)  # Apis mellifera
assert PollinatorGroup.BEE in groups

Elevation (Postgres only)

import os
from typus import PostgresRasterElevation

dsn = os.getenv("ELEVATION_DSN") or os.getenv("TYPUS_TEST_DSN")
elev = PostgresRasterElevation(dsn, raster_table=os.getenv("ELEVATION_TABLE", "elevation_raster"))

la = await elev.elevation(34.0522, -118.2437)
vals = await elev.elevations([
    (34.0522, -118.2437),  # LA
    (0.0, -30.0),          # ocean (likely None)
])

Geo helpers

from typus import latlon_to_unit_sphere
print(latlon_to_unit_sphere(31.5, -110.4))  # → x, y, z on S²

Postgres (optional for production deployments)

from typus import PostgresTaxonomyService
svc = PostgresTaxonomyService("postgresql+asyncpg://user:pw@host/db")
bee = await svc.get_taxon(630955)

Developer guide

Contributor setup and the canonical gate live in docs/contributing.md.

  • Bootstrap the repo-local dev environment

    ./dev/scripts/bootstrap-dev.sh
    
  • Run the canonical local quality gate

    make check-all
    
  • Format whole repo

    make format
    
  • Build docs

    make docs
    
  • JSON Schemas – make schemas → typus/schemas/

  • Type checking – make typecheck

  • Contributor guide – docs/contributing.md

  • SQLite fixture – uv run python scripts/gen_fixture_sqlite.py

  • Pre‑commit hooks – make dev-install

Environment Variables

  • TYPUS_TEST_DSN: Postgres DSN for tests and perf harness (e.g., postgresql+asyncpg://user:pw@host/db).
  • POSTGRES_DSN: Alternate Postgres DSN; used if TYPUS_TEST_DSN is unset.
  • Optional test/ops normalization maps legacy /ibrida-v0-r1 DSNs to /ibrida-v0.
  • ELEVATION_DSN: Optional DSN override for elevation tests; falls back to TYPUS_TEST_DSN.
  • ELEVATION_TABLE: Elevation raster table name (default: elevation_raster).
  • TYPUS_ELEVATION_TEST: Set 1 to enable guarded elevation tests.
  • Perf harness:
    • TYPUS_PERF_WRITE=1: write report to dev/agents/perf_report.md.
    • TYPUS_PERF_VERIFY=1: enable result sanity checks.
    • TYPUS_PERF_EXPLAIN=1: append PG EXPLAIN snippets.

Publishing (maintainers)

See build/typus_publish.md for tag → TestPyPI → PyPI workflow.


License

MIT © 2025 Polli Labs

Metadata

Release files for polli-typus 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polli-typus 0.7.0
File Size Uploaded Provenance Actions
polli_typus-0.7.0.tar.gz 73.9 kB Without provenance Details for polli_typus-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polli-typus 0.7.0
File Interpreter ABI Platform Actions
polli_typus-0.7.0-py3-none-any.whl Python 3 none any Details for polli_typus-0.7.0-py3-none-any.whl

Total release size: 162.3 kB

Release files / polli_typus-0.7.0.tar.gz

Download URL polli_typus-0.7.0.tar.gz
Size 73.9 kB
Tags Source
SHA-256 checksum
How to use checksums
86a58a2af83df12425ef030e55278552fc724a800e295337e2ec633f3b8f0c6f
BLAKE2b-256 checksum
How to use checksums
46649d2eb3bb7d5b8a80aa3dd09d29b664b65e5bd778d37fc538599ac1ee2260
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / polli_typus-0.7.0-py3-none-any.whl

Download URL polli_typus-0.7.0-py3-none-any.whl
Size 88.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dea4deb92846a2b5908c7e81009cc8a928f34882245caa1ab648152a30840180
BLAKE2b-256 checksum
How to use checksums
46c8f674356713fd508ec7ee6accf914e2d8d16db14690a991910ba2b8a22c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for polli-typus 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page