Metadata-Version: 2.5
Name: myopenfund-open-data-store
Version: 0.1.0
Summary: Bitemporal open-data store for MyOpenFund: contracts, writer, publisher, reader.
Project-URL: Homepage, https://github.com/MyOpenFund/open-data-store
Project-URL: Source, https://github.com/MyOpenFund/open-data-store
Project-URL: Issues, https://github.com/MyOpenFund/open-data-store/issues
Project-URL: Organization, https://github.com/MyOpenFund
Author: Marc Jeulin
Maintainer: Marc Jeulin
License-Expression: MIT
License-File: LICENSE
Keywords: bitemporal,duckdb,ducklake,finance,myopenfund,open-data,parquet
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Requires-Python: >=3.11
Requires-Dist: pyarrow>=17
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: duckdb<3,>=2.0; extra == 'dev'
Requires-Dist: openpyxl>=3.1; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: pytz>=2024.1; extra == 'dev'
Requires-Dist: pyyaml>=6; extra == 'dev'
Requires-Dist: ruff==0.17.3; extra == 'dev'
Requires-Dist: twine>=5; extra == 'dev'
Provides-Extra: publisher
Requires-Dist: duckdb<3,>=2.0; extra == 'publisher'
Requires-Dist: pytz>=2024.1; extra == 'publisher'
Provides-Extra: reader
Requires-Dist: duckdb<3,>=2.0; extra == 'reader'
Requires-Dist: openpyxl>=3.1; extra == 'reader'
Requires-Dist: pytz>=2024.1; extra == 'reader'
Provides-Extra: writer
Description-Content-Type: text/markdown

# open-data-store

Created and maintained by [Marc Jeulin](https://github.com/jeulinmarc), part of [MyOpenFund](https://github.com/MyOpenFund).

Bitemporal open-data store for MyOpenFund: dataset **contracts**, a light **writer** for producers,
a **publisher** (the only writer to the lake) and a **reader** for analyses, the MCP and strategies.
Facts are DuckLake tables (Parquet + a Postgres catalogue), read through DuckDB. Every fact carries
`valid_date` (what it is about) and `known_at` (when it became knowable): reads are look-ahead-free.

> This library is a tool. It manages nobody's money and gives no investment advice.

Renamed on 2026-11-22 (package, import, command and environment variables): see
[docs/MIGRATION.md](https://github.com/MyOpenFund/open-data-store/blob/main/docs/MIGRATION.md).

## Install

```
pip install "myopenfund-open-data-store[writer]"     # producers: pyarrow only
pip install "myopenfund-open-data-store[publisher]"  # store operator: DuckDB + DuckLake
pip install "myopenfund-open-data-store[reader]"     # analyses, MCP, strategies
```

If this environment installed the old distribution (`open-data-store`, from a git URL), run
`pip uninstall -y open-data-store` before installing `myopenfund-open-data-store`: both own the same import package.

To try the latest `main` before a release (dependencies still come from PyPI):

```
pip install "myopenfund-open-data-store[reader] @ git+https://github.com/MyOpenFund/open-data-store"
```

**Working across repos**

Clone the repos side by side and install this package editable over the PyPI version in the
consumer's environment: `pip install -e ../open-data-store`. A consumer change that needs an
unreleased version waits for this package's release before the consumer's PR merges.

**How to release**

Bump `__version__` and `version` in a PR. After it merges, go to Actions, then release, then Run workflow: pick the `main` branch and target `pypi`. Approve the `pypi` deployment. The workflow builds the package, checks it, publishes it, then creates the tag `v<version>` and the GitHub Release itself.
It fails before publishing if it is not run on the default branch or if that tag already exists. Target `testpypi` is a rehearsal: it publishes to TestPyPI and creates no tag and no release.
Pushing a tag `v<version>` by hand still works: the workflow checks that the tag equals the package version and is on the default branch, then publishes and attaches the files to the Release.
If PyPI got the package but the tag or the Release is missing, re-run the failed `github-release` job from Actions; do not push the tag by hand (the re-run would fail at the PyPI upload).

## Configuration

| Variable | Meaning |
|---|---|
| `OPEN_DATA_STORE_DATA_ROOT` | Holds `landing/` (batches), `lake/` (Parquet), `reports/` |
| `OPEN_DATA_STORE_CATALOG` | DuckLake catalogue: `postgres:dbname=... host=... user=...`, or a file path (tests, single user) |
| `OPEN_DATA_STORE_DATA_INLINING_ROW_LIMIT` | Default `0`: every batch becomes a Parquet file |
| `OPEN_DATA_STORE_KNOWN_AT_FUTURE_TOLERANCE_S` | Clock-skew tolerance, default `300` |
| `OPEN_DATA_STORE_RESOLVING_SCHEMES` | Identifier schemes that may merge entities, default `cik,lei,isin,figi,cb_code,national_id` |
| `OPEN_DATA_STORE_SINGLE_VALUED_SCHEMES` | Schemes an entity holds one value of, default `cik,lei,cb_code` |

## Reader interface (stable for v0.x)

```python
from datetime import datetime, timezone
from open_data_store.reader import Recipe, Store, export

store = Store.open()                                   # config from env (or `with Store.open() as store:`)
store.datasets()                                       # name, major, version, kind, licence, table
t = store.read_asof("fundamentals", datetime(2025, 12, 1, tzinfo=timezone.utc),
                    where="original_tag = 'us-gaap:Revenues'")  # pyarrow.Table, latest known per key
t1 = store.read_asof("fundamentals", filters={"source_code": ["sec"]},
                     columns=["entity_id", "original_tag", "value"], limit=100)  # bound, safe for servers
store.read_asof("fundamentals", filters={"entity_value": ["0000320193"]}, vintages=True)  # every vintage
store.freshness()                                      # last published_at, batch count
store.describe("fundamentals")                         # columns, docs, natural key, licence
t0 = store.read_asof("fundamentals", snapshot=42)      # what the store held at DuckLake version 42
r = Recipe("debt_by_source", "1.0.0", {"f": "fundamentals"},
           "SELECT source_code, sum(value) AS debt FROM f GROUP BY 1")
out = store.assemble(r, as_of=datetime.now(timezone.utc))  # save=True arrives with metrics
# {"f": "fundamentals:vintages"} gives every row knowable at the date, not the latest per key
export(out, "debt.xlsx")                               # .csv | .xlsx | .parquet
```

**Time zone.** The reader's sessions are pinned to UTC: timestamps come back as UTC, and `where`
and recipe SQL evaluate in UTC whatever the process `TZ`. Under a non-UTC `TZ`, earlier versions
evaluated them in local time, so a naive literal (`known_at < '2025-07-31'`) or a date cast can
select other rows now; write explicit offsets (`TIMESTAMPTZ '2025-07-31 00:00:00+02'`).

**Performance.** Filters on natural-key columns (e.g. `entity_value`) are always pushed explicitly
before the as-of window, so DuckLake reads only the matching files: on a 20-issuer test store a
filter on `entity_value` read 1 fundamentals data file (5 kB) instead of 60 files (139 kB). DuckDB
already pushes a filter on the as-of window's partition key (the natural key) through the window by
itself (filtering `entity_value` outside the window also read 1 file / 5 kB); the explicit push in
`read_asof` guarantees that pruning whatever the optimizer version. Filters on other columns read
the whole table. Keep one batch per issuer, and do not merge data files
(`ducklake_merge_adjacent_files`) without measuring: merging issuers into one file defeats the
pruning.

## Producers

```python
from open_data_store.writer import write_batch
ref = write_batch(contract, table, landing_root=data_root / "landing",
                  run_id=run_id, producer="company-corpus", source_inputs=[...])
```

The writer validates the table against its contract and drops an atomic, idempotent batch in
`landing/`. It never touches Postgres. A producer declares its own contracts through the
`open_data_store.contracts` entry-point group; standard contracts (`fundamentals`, `entity_observations`,
`filing_statements`, `filings`) ship with this library.

## Operator

```
open-data-store contracts list
open-data-store contracts approve fundamentals 3 --by <name>        # reviewed step; refuses conflicting definitions
open-data-store contracts approve filing_statements 1 --by <name>   # likewise, for a store that publishes it
open-data-store contracts approve filings 1 --by <name>             # likewise
open-data-store publish                                             # exit 0 ok · 1 fatal · 3 degraded
```

`publish` audits every landed batch again (file checksum, contract, recomputed batch id),
quarantines failures in `landing/_quarantine/` with a `reason.json`, publishes the rest atomically
(one DuckLake snapshot per batch, commit message = batch id) and writes a run report under
`reports/publisher/`. A batch that hits an infrastructure error (listed under `errors`, exit 1)
stays in `landing/` for the next run, and so do the fact batches behind a failed identity batch,
instead of being quarantined as `unknown_entity`. Those deferrals are `errors` entries too (no
separate field): their `error` text starts with `deferred:`. Design, security model and gotchas: [docs/ARCHITECTURE.md](https://github.com/MyOpenFund/open-data-store/blob/main/docs/ARCHITECTURE.md).

Producers may re-emit full history: rows already published with the same values (compared
exactly, so re-emit bit-identical floats) are skipped and counted (`skipped_rows` in the report,
`rows_skipped` in `ref.batches`, where `rows` counts only the inserted rows); the same key and
`known_at` with another value quarantines the batch (`conflicting_republish`). Columns of the
major's first approved definition are compared strictly; columns added by a later minor are compared
only where the published row holds a value (changing it is a conflict), and filling a NULL in one
needs a later `known_at` to be recorded.

## Licence

MIT (code). Each dataset carries its own data licence in its contract.
