|
| 1 | +# OSDU Python Client |
| 2 | + |
| 3 | +## Build, test, and lint commands |
| 4 | + |
| 5 | +```bash |
| 6 | +uv sync --all-extras |
| 7 | +uv run ruff check . |
| 8 | +uv build |
| 9 | +uv run pytest tests -q |
| 10 | +uv run pytest tests/search_test.py::test_search_query_records -q |
| 11 | +``` |
| 12 | + |
| 13 | +Integration tests depend on a repo-root `.env` loaded by `tests/config.py` and use MSAL interactive login from `tests/auth_fixture.py`. Tokens are cached in `.msal_token_cache.bin` by default, or at `OSDU_MSAL_CACHE_PATH` if set. |
| 14 | + |
| 15 | +Useful repository-specific maintenance commands: |
| 16 | + |
| 17 | +```bash |
| 18 | +uv run python download.py |
| 19 | +uv run python fix_openapi_json_response_media_types.py --check |
| 20 | +uv run python fix_openapi_json_response_media_types.py |
| 21 | +uv run python generate_all.py |
| 22 | +``` |
| 23 | + |
| 24 | +## High-level architecture |
| 25 | + |
| 26 | +This repository is organized around OpenAPI-driven client generation rather than handwritten runtime code. |
| 27 | + |
| 28 | +- `openapi_specs/*.json` are the source inputs for each OSDU service. |
| 29 | +- `download.py` fetches the OSDU Core Services wiki, extracts service doc links, normalizes `swagger-ui`/`/docs` URLs to JSON spec endpoints, and downloads specs with provider fallbacks (`ci`, `azure`, `aws`, `gc`). |
| 30 | +- `fix_openapi_json_response_media_types.py` patches a recurring upstream issue where structured JSON responses are declared under `*/*` instead of `application/json`. It only rewrites 2xx responses whose schemas resolve to structured payloads. |
| 31 | +- `generate_all.py` regenerates `src/osdu_python_client/<service>/` for every spec. It also patches missing `info.version` values before invoking `openapi-python-client`. |
| 32 | + |
| 33 | +Generated service packages follow the same shape: |
| 34 | + |
| 35 | +- `client.py` defines `Client` and `AuthenticatedClient`. |
| 36 | +- `api/` contains per-endpoint modules with `_get_kwargs`, `_parse_response`, `sync_detailed`, `sync`, `asyncio_detailed`, and `asyncio`. |
| 37 | +- `models/` contains generated request/response DTOs. |
| 38 | +- `types.py` and `errors.py` provide shared response wrappers and error handling. |
| 39 | + |
| 40 | +The handwritten test layer in `tests/` is the main example of intended usage. `tests/config.py` builds service URLs from a single `server` plus `*_endpoint` settings, `tests/auth_fixture.py` acquires an Azure access token with MSAL, and tests instantiate a service-specific `AuthenticatedClient` before calling generated endpoint functions and inspecting `result.parsed`. |
| 41 | + |
| 42 | +## Key conventions |
| 43 | + |
| 44 | +- Treat `src/osdu_python_client/` as generated output. Prefer changing `openapi_specs/`, `download.py`, `fix_openapi_json_response_media_types.py`, or `generate_all.py`, then regenerate. |
| 45 | +- When running tests, target `tests/` explicitly. Running `pytest` from the repo root also discovers generated `test_*.py` modules under `src/osdu_python_client/register/`, which produces collection warnings unrelated to the handwritten test suite. |
| 46 | +- Service package names come from spec filenames normalized to lowercase with spaces/hyphens converted to underscores, e.g. `Ingestion_Workflow_Service.json` becomes `osdu_python_client.ingestion_workflow_service`. |
| 47 | +- Repository tests are integration tests against a live OSDU environment, not isolated unit tests. Expect real network calls, `data_partition_id` headers, and interactive authentication if no cached MSAL token is available. |
| 48 | +- Generated endpoint helpers usually return a `Response[...]` wrapper from `sync_detailed(...)`; the parsed DTO is available on `.parsed`. Existing tests assert on `result.status_code.value` and then work with `result.parsed`. |
0 commit comments