Metadata-Version: 2.5
Name: berg-iceberg
Version: 1.16.1
Summary: A developer and operational management layer for Apache Iceberg.
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.13
Requires-Dist: filelock<5,>=3.18
Requires-Dist: psycopg2-binary<3,>=2.9
Requires-Dist: pyarrow<27,>=19
Requires-Dist: pydantic<3,>=2.11
Requires-Dist: pyiceberg[glue,hive,s3fs,sql-postgres]<0.13,>=0.12
Requires-Dist: pyyaml<7,>=6.0
Requires-Dist: rich<15,>=14
Requires-Dist: typer<0.30,>=0.27.2
Provides-Extra: controller
Requires-Dist: kopf<2,>=1.45.1; extra == 'controller'
Requires-Dist: kubernetes<38,>=37.0.1; extra == 'controller'
Description-Content-Type: text/markdown

# Berg

<!-- Release builds replace both dynamic badges with version- and channel-specific badges; Python support comes from pyproject.toml classifiers. -->
[![PyPI](https://img.shields.io/badge/PyPI-v1.16.1-blue.svg?release=1.16.1&channel=pypi)](https://pypi.org/project/berg-iceberg/)
[![Python](https://img.shields.io/badge/Python-3.13%20%7C%203.14-blue.svg?release=1.16.1&channel=pypi)](https://pypi.org/project/berg-iceberg/)

Berg is a safe management layer for Apache Iceberg catalogs and table
metadata. It helps teams inspect tables, identify health problems, describe
desired state, review deterministic changes, and execute approved operations
inside their own infrastructure.

Berg does not replace Spark, Flink, Trino, Athena, or another query engine. It
does not move or transform table records. Its focus is controlled metadata and
catalog operations with explicit approval, backend capability checks, durable
execution state, idempotency, audit history, and failure reconciliation.

## Install

With pip:

```bash
python -m pip install berg-iceberg
```

With uv:

```bash
uv tool install berg-iceberg
```

Then:

```bash
berg --version
berg --help
```

## What you can do

```bash
berg connect
berg capabilities
berg scan
berg inspect analytics.events
berg health analytics.events
berg maintenance-report analytics.events --output json
berg diff table.yaml --fail-on-drift --output json
```

Use `--output json` for automation and CI/CD integrations.

For a metadata change, Berg uses a reviewable plan:

```bash
berg plan analytics.events \
  --set-property write.target-file-size-bytes=536870912 \
  --save events-plan.json

berg apply events-plan.json --dry-run
berg apply events-plan.json --approve --audit-file audit.jsonl
berg execution-status ID --output json
```

Plans are checked against current table state and the selected backend. Berg
rejects unsupported operations, stale plans, unauthorized changes, and unsafe
duplicate execution before mutation.

For CI/CD policy gates, use `berg validate-policy` and `berg authorize` on the
exact saved plan before any execution. See the
[CI/CD integration guide](docs/ci-cd.md) and the provider-neutral examples in
[`examples/ci`](examples/ci).

Customer-managed policy bundles are versioned `berg.dev/v1` YAML or JSON
documents. They can scope allow, warning, approval, and denial rules to
operations, namespaces, and tables. Use
[`docs/policy-bundles.md`](docs/policy-bundles.md) and the example in
[`examples/policies/production.yaml`](examples/policies/production.yaml).

## Declarative table management

Portable desired-state documents and Python authoring are available in the
current package. Berg OAM table creation is available starting with Berg
1.10.0 and keeps the same portable desired-state document as its source of
truth.

Desired state can be written as a portable `berg.dev/v1` YAML or JSON document:

```bash
berg validate-spec table.yaml
berg diff table.yaml
berg plan --spec table.yaml --save table-plan.json
```

For multi-table portfolios, Berg 1.11.0 adds the `kind: TableSet` format.
`berg drift` compares the declared tables without mutation, and
`berg plan --spec-set` creates independent plans; each change still needs its
own review and approval. See the
[TableSet Python and CLI guide](docs/python-api.md#table-portfolios-v111).

Python users can author the same document without connecting to a catalog:

```python
from berg.sdk import TableDefinition

events = (
    TableDefinition.for_table("analytics.events")
    .with_column("id", "long", required=True)
    .with_column("created_at", "timestamp", required=True)
    .partition_by("created_at", transform="day")
    .sort_by("created_at", direction="desc", null_order="nulls-first")
    .with_property("write.target-file-size-bytes", "536870912")
)

events.write("events.yaml")
```

To create an actual Iceberg table from Python, use Berg OAM. Review the plan
before the explicit approval call:

```python
from berg.sdk import BergOAM, TableDefinition

events = (
    TableDefinition.for_table("analytics.events")
    .with_column("id", "long", required=True)
    .with_column("created_at", "timestamp", required=True)
    .partition_by("created_at", transform="day")
    .at_location("s3://warehouse/analytics/events")
)

oam = BergOAM(config="berg.yaml", audit_file=".berg/audit.jsonl")
plan = oam.plan_table(events)
print(plan.model_dump_json(indent=2))
result = oam.apply(plan, approve=True, actor="data-engineer")
table = oam.inspect_table("analytics.events")
```

The catalog namespace must already exist. Set the location to a path in your
own configured object store. Berg OAM manages table definitions and metadata;
use a query or compute engine for reading and writing records.
See the [Python API guide](docs/python-api.md) for policy, approval, and
supported-operation details.

### Berg 1.16.1: guarded Nessie migrations

Berg 1.16.1 extends class-based OAM migrations to an explicitly selected Nessie
Iceberg REST catalog. The migration worker adds nullable columns to an
existing table after its baseline has been registered and approved. It uses
the existing plan review, explicit approval, shared execution state, audit,
idempotency, and reconciliation path. Berg binds approval to the selected
Nessie branch and resolved REST endpoint, and does not rewrite table data.

Configure a live Nessie branch explicitly:

```yaml
catalog:
  type: rest
  compatibility_profile: nessie
  uri: http://localhost:19120/iceberg
  properties:
    maintenance_backend: native_nessie
    prefix: main
```

This route supports one `ADD_COLUMNS` transition containing nullable columns
on an existing baseline-registered table. Table-creating migrations, required
columns, destructive schema changes, partition changes, data rewrites, and
migrations on other catalog backends remain unsupported. For shared
PostgreSQL execution state, Berg skips repeat DDL after the schema is current.
The local contract covers Nessie with RustFS; it does not certify every Nessie
or object-storage deployment. For details, see the [V1.16 scope](docs/planning/scopes/V1.16_SCOPE.md),
the [Python API guide](docs/python-api.md#nessie-migration-route-v1161), and
the [compatibility matrix](docs/compatibility-matrix.md#migration-execution-support).

### Berg 1.15.0: class-based OAM and migrations

Berg 1.15.0 adds class-based table models and versioned, reviewable metadata
migrations. Models compile to Berg's existing desired-state model, so Python
classes and the CLI use the same validation and guarded execution path:

```python
from berg.sdk import Column, TableModel, partition


class Events(TableModel):
    __table__ = "analytics.events"
    __location__ = "s3://warehouse/analytics/events"
    __partitioning__ = (partition("created_at", transform="day"),)

    event_id = Column("long", required=True)
    created_at = Column("timestamp", required=True)
```

Migration files are typed data snapshots. Berg can generate them from a model,
load them without executing migration source, and preview the resulting plan.
In this release, guarded migration execution supports one metadata-only
`ADD_COLUMNS` transition containing one or more nullable columns on an
existing baseline-registered table in a local PyIceberg SQLite `SqlCatalog`
with a `file://` location. Berg's execution state may use SQLite or PostgreSQL.
Migration roots that create a table and other catalog/transition combinations
are blocked before approval or mutation. This limitation is specific to
migrations; other Berg operations retain their own backend capability matrix.
See the [Python API guide](docs/python-api.md#class-based-migrations-v115)
for the complete workflow and safety boundaries.

Policies can be authored with the same typed SDK:

```python
from berg.sdk import PolicyDefinition

PolicyDefinition.for_policy("production") \\
    .require_approval("review-properties", operations=("SET_PROPERTY",)) \\
    .write("production-policy.yaml")
```

## Supported catalog paths

Berg has compatibility contracts for:

- Iceberg REST Catalog with S3-compatible storage
- Project Nessie
- Apache Polaris
- JDBC/PostgreSQL catalogs
- Hive Metastore
- AWS Glue Catalog with S3

Support is operation- and backend-specific. Run `berg capabilities` and read
the [compatibility matrix](docs/compatibility-matrix.md) before enabling an
operation in automation.

## Customer-local Agent

The Agent runs the same guarded execution kernel inside customer
infrastructure. It receives an approved plan, uses customer credentials, and
writes state and audit records locally. It requires no inbound service and
does not upload raw table data to Berg Cloud.

```bash
berg agent apply plan.json --approve
berg agent status --output json
```

An approved plan can also be submitted to the local Docker adapter. Use a
digest-pinned Agent image and customer-managed credentials:

```bash
berg job run plan.json --approve \
  --image-ref ghcr.io/berg-cloud/berg-agent:<release>@sha256:<64-hex-digest> \
  --env-file .berg/customer.env --output json
```

The Docker adapter claims the same durable execution state used by direct
Agent execution. It never treats a container exit alone as proof of a catalog
commit; uncertain outcomes remain UNKNOWN until explicitly reconciled. See
the [local Docker job adapter guide](docs/docker-job-adapter.md).

For customer-managed Kubernetes execution, use the Kubernetes Job adapter with
PostgreSQL shared execution state and Secret references. See the
[Kubernetes Job adapter guide](docs/kubernetes-job-adapter.md).

For teams submitting work through Kubernetes, Berg 1.9 adds the namespaced
`berg.dev/v1` BergJob API and customer-managed controller. The controller
checks approval, policy, table freshness, and backend capability before it
starts one hardened Agent Job. PostgreSQL remains the shared authority for
approval, idempotency, leases, and execution results; the controller does not
perform Iceberg mutations. The customer runs the controller, Agent, catalog
access, credentials, and shared state in its own infrastructure. See the
[Kubernetes controller installation and operations guide](docs/kubernetes-controller.md)
for storage, RBAC, upgrade, failure recovery, and uninstall requirements.

`berg maintenance-report` and `berg agent status` are read-only operational
commands. Maintenance reports explain recommendations and backend blocks;
Agent status includes the versioned status/heartbeat envelope and local inbox,
processing, and quarantine counts.

The reference container deployment is in
[docker-compose.agent.yml](docker-compose.agent.yml).

## Local development

The private conformance repository contains disposable Docker environments and
live compatibility contracts. The core repository contains the installable
package and its offline test suite:

```bash
git clone https://github.com/Berg-Cloud/berg.git
cd berg
uv sync --group dev
uv run pytest
```

See the [conformance repository](https://github.com/Berg-Cloud/berg-conformance)
for local catalog stacks. See [local development](docs/local-development.md), the
[capability matrix](docs/capabilities.md), and the
[Python API guide](docs/python-api.md) for details.

The live backend matrix and disposable acceptance environments are maintained
in the private [Berg Conformance repository](https://github.com/Berg-Cloud/berg-conformance).
See the [repository topology](docs/repository-topology.md) for the ownership
and migration rules.

## Safety boundaries

Berg supports approved metadata operations such as properties, compatible
schema additions, additive partition fields, certified snapshot expiration,
explicitly guarded orphan-file cleanup, and default sort-order updates for
future writers. V1.6 requires a reviewed candidate manifest, positive age and
reference evidence, approval, stale-state and capability checks, locking,
idempotency, and audit before any object is deleted.

V1.14 adds opt-in bounded bin-pack data-file compaction through a
customer-managed Spark worker. Stable capability is limited to AWS Glue/S3
with Spark 4.0.5 or 4.1.4, Iceberg 1.12.0, and Scala 2.13. The normal Berg plan,
policy, approval, idempotency, audit, and reconciliation checks apply. Berg
does not read or transform table records, and compaction is not scheduled or
applied automatically. Other catalog/runtime combinations remain blocked.
See the [V1.14.0 release certification](docs/v1.14.0-release-certification.md),
[V1.6.2 release certification](docs/v1.6.2-release-certification.md), and
[V1.13.0 release certification](docs/v1.13.0-release-certification.md).

The current roadmap and complete version-scope history are organized in the
[Berg planning index](docs/planning/README.md).

## License and security

See [SECURITY.md](SECURITY.md) for vulnerability reporting and
[docs/security.md](docs/security.md) for the operational security model.
