Skip to main content
bovidaeta logo

bovidaeta

PyPI Python versions DOI License

A common data format for dairy cattle data.

Dairy data comes from many places: herd management software, milk recording organizations, milking robots, activity sensors and vet records, each in its own format. bovidaeta gives them one shape: herds, cows and a timeline of animal_events per cow (calvings, milk recordings, diagnoses, treatments, and so on). Code written against bovidaeta works for any farm whose data has been converted to it.

bovidaeta is developed by the Bovi-Analytics lab at Cornell University.

What's in the package

  • Data models: pydantic models for herds, cows and events, plus typed metadata for each event type, so data is validated as you write it. Data from research studies fits in too: Study and StudyAnimal describe a study and its animals, and events record the study they came from.
  • Two storage formats: one SQLite file per farm (on a laptop or an edge device on the farm), or Delta tables holding many farms (in Databricks). The table definitions ship with the package.
  • DairyData: one loader for both stores, with filters for date range, event type, cows, herds and studies; so you don't need to write SQL.
  • Lactation helpers: derive lactations and days in milk from the events.
  • A farm simulator: generates a realistic-looking farm database, so you can try everything without real data.

Installation

pip install bovidaeta

To read Delta tables outside Databricks, install the Spark extra (inside a Databricks notebook, Spark is already there):

pip install 'bovidaeta[delta]'

bovidaeta supports Python 3.10 and newer.

Quick start

1. Get some data

Don't have data in this format yet? Simulate a farm:

python -m bovidaeta.simulation --animals 200 --years 2 --db dairy_farm.db --seed 1 --yes

2. Load events

from datetime import datetime, timezone

from bovidaeta import DairyData, EventType

data = DairyData.from_sqlite("dairy_farm.db")

milk = data.load_events(
    dts_start=datetime(2025, 1, 1, tzinfo=timezone.utc),
    subset_events=[EventType.MILK_RECORDING],
    subset_metadata=["milking_yield", "fat_percentage", "protein_percentage"],
)
print(milk.head())  # a polars DataFrame

load_cows(), load_herds(), load_studies() and load_study_animals() work the same way. Use the filters: farm event tables get large fast.

3. Work with lactations

from bovidaeta import load_lactation_records, load_lactations, select_lactations

lactations = load_lactations(data)
latest = select_lactations(lactations, "latest")
records = load_lactation_records(data, lactations=latest, max_dim=305)

Milk meter data can come as individual milkings and as daily totals. load_daily_milk_yields gives one yield per cow per day from both, never adding them up: daily totals by default, or measured milkings with prefer="milkings". load_lactation_records(..., event_type=None) attaches those to lactations.

from bovidaeta import load_daily_milk_yields

daily = load_daily_milk_yields(data, dts_start="2026-01-01")

4. Create records yourself

from datetime import date, datetime, timezone
from uuid import uuid4

from bovidaeta import AnimalGender, Cow, Event, EventType, Herd, MilkRecordingMetadata

herd = Herd(herd_id=uuid4(), name="Example farm", country_code="US")
cow = Cow(
    animal_id=uuid4(),
    herd_id=herd.herd_id,
    gender=AnimalGender.FEMALE,
    birth_date=date(2021, 3, 14),
    exit_date=None,  # still on the farm
)
event = Event(
    event_id=uuid4(),
    event_type=EventType.MILK_RECORDING,
    animal_id=cow.animal_id,
    animal_id_source="1234",  # the cow's ID in the system the data came from
    datetime=datetime.now(timezone.utc),
    metadata=MilkRecordingMetadata(milking_yield=38.5, fat_percentage=4.1).model_dump(),
)

Using Databricks (Delta Lake)

For many farms at once, bovidaeta data can live in Delta tables in Unity Catalog:

  1. Create the tables by running schemas/delta.sql once in a SQL editor (set your catalog and schema at the top).
  2. Load per-farm SQLite files into them with the pipelines/sqlite_to_delta.py notebook.
  3. Read them with the same loader:
data = DairyData.from_delta("bovidaeta.farms")  # your catalog.schema
df = data.load_events(subset_events=[EventType.MILK_RECORDING])  # a Spark DataFrame

The filters are identical, but from_delta returns Spark DataFrames instead of polars ones, so analysis code needs some changes when you move between the two. bovidaeta.to_polars() converts a small Spark result to polars. See src/bovidaeta/io/README.md for the details.

Learn more

Repository layout

src/bovidaeta/
├── cow.py, herd.py, event.py,   data models
│   study.py, event_metadata.py,
│   enums.py
├── io/                          DairyData, one backend per store
├── lactation.py                 lactations and days in milk
├── schemas/                     SQLite and Delta table definitions, migrations
└── simulation/                  farm simulator
examples/                        runnable walkthroughs
pipelines/                       SQLite -> Delta load job (Databricks)

Contributing

Contributions are welcome. See CONTRIBUTING.md to set up a development environment and open a pull request.

Citing

If you use bovidaeta in your research, please cite it using its DOI, 10.5281/zenodo.24348211, which always points to the latest release (each release also has its own DOI on Zenodo). See CITATION.cff, or use "Cite this repository" on GitHub.

License

bovidaeta is licensed under the Apache License 2.0. You're free to use it, including commercially. If you redistribute it, include the NOTICE file, as the license requires.

Metadata

Release files for bovidaeta 0.5.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 bovidaeta 0.5.0
File Size Uploaded Provenance Actions
bovidaeta-0.5.0.tar.gz 112.1 kB With provenance Details for bovidaeta-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bovidaeta 0.5.0
File Interpreter ABI Platform Actions
bovidaeta-0.5.0-py3-none-any.whl Python 3 none any Details for bovidaeta-0.5.0-py3-none-any.whl

Total release size: 184.4 kB

Release files / bovidaeta-0.5.0.tar.gz

Download URL bovidaeta-0.5.0.tar.gz
Size 112.1 kB
Tags Source
SHA-256 checksum
How to use checksums
644d6f60d3fd0cf7db980fdea2345b5302b9ed99ab2f1019fcc0bb98b11b885a
BLAKE2b-256 checksum
How to use checksums
32306eac2c586293bc5070b6da69b919e2def6e27a11f9f3f45ac39b0d462af8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / bovidaeta-0.5.0-py3-none-any.whl

Download URL bovidaeta-0.5.0-py3-none-any.whl
Size 72.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
933f3e93e381110581166a58041ae8aabac6eade42a7ab14630d32708d87b6d4
BLAKE2b-256 checksum
How to use checksums
f32b5357bc4f62be0f76fe380082eb7b0396fd22f3f5e668b009c70f975ca762
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for bovidaeta 0.5.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bovidaeta-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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