Skip to main content
bovidaeta logo

bovidaeta

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.
  • 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 and herds; 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() and load_herds() 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
│   event_metadata.py, enums.py
├── io/                          DairyData, one backend per store
├── lactation.py                 lactations and days in milk
├── schemas/                     SQLite and Delta table definitions
└── 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. 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.2.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.2.0
File Size Uploaded Provenance Actions
bovidaeta-0.2.0.tar.gz 100.4 kB With provenance Details for bovidaeta-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 162.6 kB

Release files / bovidaeta-0.2.0.tar.gz

Download URL bovidaeta-0.2.0.tar.gz
Size 100.4 kB
Tags Source
SHA-256 checksum
How to use checksums
062bd90d466348c7db6ff4fb7f401e27a4e1f0c655d24714d8974a9d2de954f7
BLAKE2b-256 checksum
How to use checksums
b8eb022283aa5142aacfcdecfc93f057057a5ff6236eac1140b22cedf20a15b7
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 18, 2026.

Transparency log

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

Download URL bovidaeta-0.2.0-py3-none-any.whl
Size 62.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b2d00f22bf8358ee1dccce3572978d8fe60fd47cdcaaf2c41014442b60aa05a
BLAKE2b-256 checksum
How to use checksums
304e18ccdd2223e595509843d9b9d4462a1e741fcf8e1e30ab16f2be0486ed49
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 18, 2026.

Transparency log

Security for bovidaeta 0.2.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.2.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 18, 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