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. Data from research studies fits in too:
StudyandStudyAnimaldescribe 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:
- Create the tables by running
schemas/delta.sqlonce in a SQL editor (set your catalog and schema at the top). - Load per-farm SQLite files into them with the
pipelines/sqlite_to_delta.pynotebook. - 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
src/bovidaeta/io/README.md: loading data, filters, and how the two stores differexamples/: runnable walkthroughs for SQLite and Databrickssrc/bovidaeta/simulation/README.md: the farm simulatorsrc/bovidaeta/enums.pyandevent_metadata.py: every event type and its metadata fieldsschemas/: the SQLite and Delta table definitions, and migrations for databases created with an older version
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.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bovidaeta-0.4.0.tar.gz | 111.2 kB | With provenance | Details for bovidaeta-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bovidaeta-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for bovidaeta-0.4.0-py3-none-any.whl |
Total release size: 183.0 kB
Release files / bovidaeta-0.4.0.tar.gz
| Download URL | bovidaeta-0.4.0.tar.gz |
|---|---|
| Size | 111.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
207466a312b68692ef077cd556bef07f43edf9cfc5512fcefc84ed8543c93952
|
|
BLAKE2b-256 checksum How to use checksums |
575cc5fe6674378363628d119901c9a670b67a20a18b1aa603a2b810639f0666
|
| 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 24, 2026.
Transparency logRelease files / bovidaeta-0.4.0-py3-none-any.whl
| Download URL | bovidaeta-0.4.0-py3-none-any.whl |
|---|---|
| Size | 71.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd90a76bfeeb3322ec2cfc411b377c4e98a440a521dddc5ac923b937c6622651
|
|
BLAKE2b-256 checksum How to use checksums |
21ea2ff4c610a9ce09873a60805f4c4ec13c08a61f3eca2d1afd29e7e3706e27
|
| 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 24, 2026.
Transparency logSecurity for bovidaeta 0.4.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.
Attestation for bovidaeta-0.4.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 24, 2026.
Transparency logA 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.