Skip to content

Docker

Run agrobr without installing Python locally.

Requirements

Build

docker build -t agrobr .

Interactive use

docker run -it --rm agrobr

Opens a Python REPL with agrobr installed:

>>> from agrobr.sync import cepea
>>> df = cepea.indicador('soja', inicio='2024-01-01')
>>> print(df.head())

CLI

docker run --rm agrobr agrobr --version
docker run --rm agrobr agrobr cepea indicador boi
docker run --rm agrobr agrobr conab safras soja

Persisting the cache

Without a volume mount, the DuckDB cache is lost when the container exits.

docker run -it --rm -v agrobr-cache:/home/agrobr/.agrobr agrobr

The named volume agrobr-cache persists across runs.

Running local scripts

docker run --rm -v "$(pwd)":/work agrobr python /work/my_script.py

Extras

The default image already includes the browser (Playwright + Chromium) and pdf (pdfplumber) extras, required by CONAB and by ANDA, ANEC, UNICA, Lista Suja (PDF route), Rio Verde and the INCRA case status, respectively.

--build-arg EXTRAS replaces the default, and browser must stay in the list: the build always runs playwright install chromium. To add extras, include the defaults:

docker build --build-arg EXTRAS="browser,pdf,polars" -t agrobr:extras .

Compatibility

Extra Docker Notes
browser yes (default) Playwright + Chromium. Required for CONAB
pdf yes (default) pdfplumber, pure Python. Required for ANDA, ANEC, UNICA, Lista Suja (PDF route), Rio Verde and the INCRA case status
polars yes Pre-built manylinux wheels
bigquery yes Google Cloud client
geo uncertain geopandas/pyogrio may work (GDAL bundled in the wheel). Not verified
dev don't use Dev tooling (pytest, ruff, mypy)
docs don't use mkdocs

Python version

The default image uses Python 3.11. For other versions:

docker build --build-arg PYTHON_VERSION=3.12 -t agrobr:py312 .

Supported versions: 3.11, 3.12, 3.13.

Environment variables

All settings are customizable via env vars:

docker run -it --rm \
  -e AGROBR_CACHE_DIR=/data/cache \
  -e AGROBR_HTTP_TIMEOUT_READ=60 \
  -e AGROBR_HTTP_MAX_RETRIES=5 \
  -v agrobr-data:/data \
  agrobr
Prefix Setting
AGROBR_CACHE_ Cache directory, DuckDB database name
AGROBR_HTTP_ Timeouts, retries, per-source rate limits
AGROBR_ALERT_ Slack/Discord webhooks, SendGrid

The full list is in Environment variables.

Limitations

  • Ephemeral cache without a volume mount. Use -v agrobr-cache:/home/agrobr/.agrobr.
  • Image ~2.3GB (Chromium ~1.5GB + pandas ~100MB + duckdb ~80MB + other deps).
  • agrobr/data/censo_1985/ — the 1985 municipal census Parquet package (8.8 MB, plus the 68 KB coverage file and the manifest) ships in the image; it is what ibge.censo_agro_municipal_1985() reads, with no network.