diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91a2b8f..d0bfd61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: - name: Check generated models match the spec run: | just codegen - git diff --exit-code src/pdc_api_client/_generated.py + git diff --exit-code src/pdc_api/_generated.py zizmor: name: Zizmor audit diff --git a/AGENTS.md b/AGENTS.md index 60b6676..4a18bf8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,24 +1,24 @@ This file guides AI agents (Claude, Codex, and others) working in this repository. -# pdc-python-client +# pdc-api-python -A framework-free Python client for the Philanthropy Data Commons (PDC) API. The distribution is `pdc-python-client`; the import name is `pdc_api_client`. `README.md` is the user-facing documentation and `CONTRIBUTING.md` the developer documentation; keep both accurate when you change behavior. +A framework-free Python client for the Philanthropy Data Commons (PDC) API. The distribution is `pdc-api`; the import name is `pdc_api`. `README.md` is the user-facing documentation and `CONTRIBUTING.md` the developer documentation; keep both accurate when you change behavior. ## Boundaries - No framework dependency, and no reference to any particular consumer in code, comments, or tests. Configuration arrives as arguments (`base_url`, `timeout`, a `TokenProvider`), never from settings or the environment. The integration tests are the one place that reads environment variables. -- Optional features live in extras: `pdc_api_client.testing` needs `[testing]`, `pdc_api_client.seeding` needs `[seeding]`. The core imports neither. +- Optional features live in extras: `pdc_api.testing` needs `[testing]`, `pdc_api.seeding` needs `[seeding]`. The core imports neither. ## Models and codegen -- `src/pdc_api_client/_generated.py` is generated from `src/pdc_api_client/openapi.json` by `just codegen`. Never edit it by hand, and import models from `pdc_api_client.models`. +- `src/pdc_api/_generated.py` is generated from `src/pdc_api/openapi.json` by `just codegen`. Never edit it by hand, and import models from `pdc_api.models`. - Generated code owns field shapes. `models.py` owns client concerns: bundle `pdc_endpoint` and `default_page_size` ClassVars, aliases, and write-only request models. `permission_grants.py` models the grant union by hand. - After `just update-api-spec`, record the spec's `info.version` and the download date in `CHANGELOG.md`; PDC changes the spec without bumping that version. - When the spec disagrees with what PDC returns, add a rule to `codegen/preprocess.py` with a one-line comment naming the mismatch, then regenerate. Delete a rule once PDC fixes the cause. CI fails if `_generated.py` drifts from the spec. ## API conventions -- `session` is the first positional argument; every other argument is keyword-only. The exception is the bundle type in `get_bundle_page` and `pdc_api_client.testing.add_page_response`, which names the endpoint. +- `session` is the first positional argument; every other argument is keyword-only. The exception is the bundle type in `get_bundle_page` and `pdc_api.testing.add_page_response`, which names the endpoint. - Errors end in `Error`, except the base class `PDCException`. A lookup's not-found error subclasses `PDCNotFoundError`. ## Commands diff --git a/CHANGELOG.md b/CHANGELOG.md index 11eb532..a677413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ PDC does not bump its spec version for every API change, so each entry names the Breaking changes that make names consistent before a wider release: +- The distribution is now `pdc-api` (was `pdc-python-client`), the import name is `pdc_api` (was `pdc_api_client`), and the repository is `PhilanthropyDataCommons/pdc-api-python`. - `get_basefields` is now `get_base_fields`, `create_changemaker_proposal` is `create_proposal`, `create_changemaker_proposal_version` is `create_proposal_version`, and `register_file_upload` is `create_file`. - `get_application_form` takes `application_form_id` instead of `form_id`. - `list_permission_grants` filters by `changemaker_id`, `funder_short_code`, and `proposal_id` instead of `changemaker`, `funder`, and `proposal`. @@ -18,7 +19,7 @@ Breaking changes that make names consistent before a wider release: Other changes: -- `ChangemakerFieldValueBatchNotFoundError` and `TokenRequestError` can be imported from `pdc_api_client`. +- `ChangemakerFieldValueBatchNotFoundError` and `TokenRequestError` can be imported from `pdc_api`. ## 0.3.0 (2026-11-18) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6130110..3aa5618 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,8 +49,8 @@ gh run download -n coverage-json ## Updating to a new PDC spec ```bash -just update-api-spec # download the current spec into src/pdc_api_client/openapi.json -just codegen # regenerate src/pdc_api_client/_generated.py +just update-api-spec # download the current spec into src/pdc_api/openapi.json +just codegen # regenerate src/pdc_api/_generated.py just check ``` diff --git a/README.md b/README.md index 6f2526b..d9b27e9 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# pdc-python-client +# pdc-api-python A Python client for the [Philanthropy Data Commons](https://philanthropydatacommons.org) (PDC) API. PDC is an access-controlled service where changemakers and funders share funding proposals and organization data. A changemaker can submit a proposal once and share it with any funder it chooses, and the data owner decides who sees what. This package wraps the [PDC API](https://api.philanthropydatacommons.org/) in typed Pydantic models, handles pagination, and raises one exception class per HTTP error. It doesn't depend on any web framework. -Install it as `pdc-python-client` and import it as `pdc_api_client`. +Install it as `pdc-api` and import it as `pdc_api`. > **Status:** alpha. The API may change between minor versions until 1.0. @@ -13,13 +13,13 @@ Install it as `pdc-python-client` and import it as `pdc_api_client`. The package is not on PyPI yet. Install it from a tagged release on GitHub: ```bash -pip install "pdc-python-client @ git+https://github.com/PhilanthropyDataCommons/pdc-python-client@v0.3.0" +pip install "pdc-api @ git+https://github.com/PhilanthropyDataCommons/pdc-api-python@v0.3.0" ``` or with uv: ```bash -uv add git+https://github.com/PhilanthropyDataCommons/pdc-python-client --tag v0.3.0 +uv add git+https://github.com/PhilanthropyDataCommons/pdc-api-python --tag v0.3.0 ``` Two optional extras add test and seeding helpers: @@ -27,16 +27,16 @@ Two optional extras add test and seeding helpers: - **`testing`:** helpers for mocking PDC responses in your own tests, built on [`responses`](https://github.com/getsentry/responses). - **`seeding`:** helpers for creating PDC and Keycloak test data, built on [`python-keycloak`](https://github.com/marcospereirampj/python-keycloak) and [Faker](https://github.com/joke2k/faker). -Add them to the requirement, as in `"pdc-python-client[testing,seeding] @ git+https://github.com/PhilanthropyDataCommons/pdc-python-client@v0.3.0"`. +Add them to the requirement, as in `"pdc-api[testing,seeding] @ git+https://github.com/PhilanthropyDataCommons/pdc-api-python@v0.3.0"`. Python 3.12 or later is required. ## Quickstart ```python -from pdc_api_client import APISession -from pdc_api_client.client import get_changemakers, get_proposal -from pdc_api_client.token import KeycloakClientCredentialsProvider +from pdc_api import APISession +from pdc_api.client import get_changemakers, get_proposal +from pdc_api.token import KeycloakClientCredentialsProvider session = APISession( base_url="https://api.philanthropydatacommons.org/", @@ -55,7 +55,7 @@ for changemaker in get_changemakers(session): proposal = get_proposal(session, proposal_id=42) ``` -Every response is parsed into a model from `pdc_api_client.models`, with snake_case attributes over PDC's camelCase fields. +Every response is parsed into a model from `pdc_api.models`, with snake_case attributes over PDC's camelCase fields. ## Authentication @@ -80,7 +80,7 @@ There are two ways to read a list. **Iterate everything.** `get_changemakers`, `get_funders`, `get_proposals`, `get_initiatives`, and the other plural `get_*` functions are generators that walk every page for you. The exception is `get_base_fields`, which returns a list: ```python -from pdc_api_client.client import get_changemaker_proposals +from pdc_api.client import get_changemaker_proposals for link in get_changemaker_proposals(session, changemaker_id=7): print(link.proposal_id) @@ -89,8 +89,8 @@ for link in get_changemaker_proposals(session, changemaker_id=7): **Fetch one page.** `get_bundle_page` returns a single page as a bundle, which is what a paginated UI needs. It takes the bundle type, a page number, an optional page size, and an optional search string: ```python -from pdc_api_client.client import get_bundle_page -from pdc_api_client.models import FunderBundle +from pdc_api.client import get_bundle_page +from pdc_api.models import FunderBundle page = get_bundle_page(session, FunderBundle, page=2, count_per_page=25, content="climate") print(page.total, [funder.name for funder in page.entries]) @@ -103,8 +103,8 @@ Bundles for nested endpoints take path parameters, such as `get_bundle_page(sess The client covers the writes a proposal workflow needs: creating a proposal, adding a version with field values, linking a changemaker to it, and uploading files. ```python -from pdc_api_client.client import create_proposal, create_proposal_version -from pdc_api_client.models import NewProposalFieldValue, NewProposalVersion +from pdc_api.client import create_proposal, create_proposal_version +from pdc_api.models import NewProposalFieldValue, NewProposalVersion proposal = create_proposal(session, data={"opportunityId": 5, "externalId": "app-2026-001"}) version = create_proposal_version( @@ -126,11 +126,11 @@ Uploading a file takes two steps. `create_file` creates the file record and retu ## Permission grants -PDC controls access with permission grants. Each grant gives a grantee (a user, a Keycloak organization, or every authenticated user) a set of verbs (such as `view` or `edit`) over a set of scopes, in the context of one entity such as a changemaker or a proposal. `pdc_api_client.permission_grants` models each context as its own class, so a grant parses into, say, `ChangemakerPermissionGrant` with a typed `changemaker_id`: +PDC controls access with permission grants. Each grant gives a grantee (a user, a Keycloak organization, or every authenticated user) a set of verbs (such as `view` or `edit`) over a set of scopes, in the context of one entity such as a changemaker or a proposal. `pdc_api.permission_grants` models each context as its own class, so a grant parses into, say, `ChangemakerPermissionGrant` with a typed `changemaker_id`: ```python -from pdc_api_client.models import PermissionGrantEntityType, PermissionGrantGranteeType, PermissionGrantVerb -from pdc_api_client.permission_grants import ChangemakerPermissionGrant, create_permission_grant, list_permission_grants +from pdc_api.models import PermissionGrantEntityType, PermissionGrantGranteeType, PermissionGrantVerb +from pdc_api.permission_grants import ChangemakerPermissionGrant, create_permission_grant, list_permission_grants grant = create_permission_grant( session, @@ -150,7 +150,7 @@ The models check that the grantee fields match `grantee_type` before anything is ## Errors -`APISession` raises a subclass of `pdc_api_client.PDCException` for every failed request. Each exception has `.code` (the HTTP status) and `.detail` (the parsed JSON body, or the raw text when the body isn't JSON). Before raising, it retries a GET or HEAD up to three times on a 502, 503, or 504 or a dropped connection. +`APISession` raises a subclass of `pdc_api.PDCException` for every failed request. Each exception has `.code` (the HTTP status) and `.detail` (the parsed JSON body, or the raw text when the body isn't JSON). Before raising, it retries a GET or HEAD up to three times on a 502, 503, or 504 or a dropped connection. | Status | Exception | | ------------- | ----------------------------- | @@ -175,7 +175,7 @@ A few lookups raise a subclass of `PDCNotFoundError` named for the resource: ## Models -Most models are generated from PDC's OpenAPI spec, which is pinned in `src/pdc_api_client/openapi.json`. Import them from `pdc_api_client.models`; `pdc_api_client._generated` is an implementation detail. +Most models are generated from PDC's OpenAPI spec, which is pinned in `src/pdc_api/openapi.json`. Import them from `pdc_api.models`; `pdc_api._generated` is an implementation detail. The models ignore fields they don't declare. When PDC adds a field to a response, parsing keeps working, and the new field appears once the models are regenerated. @@ -186,21 +186,21 @@ The spec doesn't always match what PDC returns. Some fields it marks required ar The client covers most of the API but not all of it: - **No client functions:** `/applicationFormFields`, `/sources` (apart from `create_changemaker_source`), `/tasks` (bulk uploads and base field copies), `/terminologySets`, and `/users`. Their models are generated, and `session.get`/`session.post` reach any endpoint directly. -- **Other writes:** creating funders, changemakers, opportunities, and funder or data-provider sources is possible only through the seeding helpers in `pdc_api_client.seeding`, which aren't meant for production data. +- **Other writes:** creating funders, changemakers, opportunities, and funder or data-provider sources is possible only through the seeding helpers in `pdc_api.seeding`, which aren't meant for production data. - **Async:** the client is synchronous and built on `requests`. Issues and pull requests that fill these gaps are welcome. ## Testing your code -`pdc_api_client.testing` (extra: `testing`) registers mocked PDC responses with `responses`. It has payload builders that return valid response bodies, and `add_*_response` functions that register them for a base URL: +`pdc_api.testing` (extra: `testing`) registers mocked PDC responses with `responses`. It has payload builders that return valid response bodies, and `add_*_response` functions that register them for a base URL: ```python import responses -from pdc_api_client import APISession, testing -from pdc_api_client.client import get_bundle_page -from pdc_api_client.models import ChangemakerBundle +from pdc_api import APISession, testing +from pdc_api.client import get_bundle_page +from pdc_api.models import ChangemakerBundle BASE_URL = "https://pdc.test/" @@ -229,10 +229,10 @@ def test_lists_changemakers(): ## Seeding a PDC stack -`pdc_api_client.seeding` (extra: `seeding`) creates realistic data on a PDC stack through the public PDC API and the Keycloak admin API. It is for local development and integration tests, not production: +`pdc_api.seeding` (extra: `seeding`) creates realistic data on a PDC stack through the public PDC API and the Keycloak admin API. It is for local development and integration tests, not production: -- **`pdc_api_client.seeding.pdc_entities`:** `seed_*` functions for funders, collaboratives, changemakers, fiscal sponsorships, data providers, opportunities, application forms, proposals, initiatives, and field values. `seed_proposal_bundle` creates a full proposal and everything it depends on in one call. -- **`pdc_api_client.seeding.keycloak_admin`:** `KeycloakAdmin`, whose `ensure_*` methods create Keycloak organizations, users, memberships, and realm roles only if they don't already exist, so re-running a seed script is safe. +- **`pdc_api.seeding.pdc_entities`:** `seed_*` functions for funders, collaboratives, changemakers, fiscal sponsorships, data providers, opportunities, application forms, proposals, initiatives, and field values. `seed_proposal_bundle` creates a full proposal and everything it depends on in one call. +- **`pdc_api.seeding.keycloak_admin`:** `KeycloakAdmin`, whose `ensure_*` methods create Keycloak organizations, users, memberships, and realm roles only if they don't already exist, so re-running a seed script is safe. ## Contributing diff --git a/codegen/postprocess.py b/codegen/postprocess.py index 6f2de0e..fb24d3f 100644 --- a/codegen/postprocess.py +++ b/codegen/postprocess.py @@ -1,7 +1,7 @@ import sys from pathlib import Path -BANNER = "# Generated by `just codegen` from src/pdc_api_client/openapi.json. Do not edit.\n" +BANNER = "# Generated by `just codegen` from src/pdc_api/openapi.json. Do not edit.\n" def postprocess(source: str) -> str: diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 7109923..c5da731 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -4,17 +4,17 @@ import pytest import requests -from pdc_api_client.models import FunderCollaborativeMemberBundle -from pdc_api_client.seeding.keycloak_admin import KeycloakAdmin -from pdc_api_client.seeding.pdc_entities import ( +from pdc_api.models import FunderCollaborativeMemberBundle +from pdc_api.seeding.keycloak_admin import KeycloakAdmin +from pdc_api.seeding.pdc_entities import ( SeededFunderCollaborative, SeededProposalBundle, seed_funder_collaborative_with_members, seed_proposal_bundle, seed_proposal_corpus, ) -from pdc_api_client.token import KeycloakClientCredentialsProvider -from pdc_api_client.transport import APISession +from pdc_api.token import KeycloakClientCredentialsProvider +from pdc_api.transport import APISession PDC_API_URL = os.environ.get("PDC_API_URL", "http://localhost:3030") KEYCLOAK_SERVER_URL = os.environ.get("KEYCLOAK_SERVER_URL", "http://pdc-auth:8780") diff --git a/integration_tests/test_application_form_input_type_contract.py b/integration_tests/test_application_form_input_type_contract.py index 913ea04..a31e889 100644 --- a/integration_tests/test_application_form_input_type_contract.py +++ b/integration_tests/test_application_form_input_type_contract.py @@ -2,10 +2,10 @@ import pytest -from pdc_api_client.client import get_application_form -from pdc_api_client.errors import PDCBadRequestError -from pdc_api_client.models import ChangemakerApplicationForm -from pdc_api_client.seeding.pdc_entities import seed_application_form, seed_base_field, seed_opportunity +from pdc_api.client import get_application_form +from pdc_api.errors import PDCBadRequestError +from pdc_api.models import ChangemakerApplicationForm +from pdc_api.seeding.pdc_entities import seed_application_form, seed_base_field, seed_opportunity SPEC_ENUM_VALUES = ["shortText", "longText", "radio", "dropdown", "multiselect", "hidden"] diff --git a/integration_tests/test_default_permission_grants.py b/integration_tests/test_default_permission_grants.py index 561c4d5..0f2f94a 100644 --- a/integration_tests/test_default_permission_grants.py +++ b/integration_tests/test_default_permission_grants.py @@ -2,8 +2,8 @@ import pytest -from pdc_api_client.errors import PDCNotFoundError -from pdc_api_client.permission_grants import ( +from pdc_api.errors import PDCNotFoundError +from pdc_api.permission_grants import ( DefaultPermissionGrant, PermissionGrantEntityType, PermissionGrantGranteeType, diff --git a/integration_tests/test_ensure_for_keycloak_org.py b/integration_tests/test_ensure_for_keycloak_org.py index cd7f967..8e7b904 100644 --- a/integration_tests/test_ensure_for_keycloak_org.py +++ b/integration_tests/test_ensure_for_keycloak_org.py @@ -1,4 +1,4 @@ -from pdc_api_client.seeding.pdc_entities import ( +from pdc_api.seeding.pdc_entities import ( ensure_changemaker_for_keycloak_org, ensure_data_provider_for_keycloak_org, ensure_funder_for_keycloak_org, diff --git a/integration_tests/test_group_membership.py b/integration_tests/test_group_membership.py index dfb3305..3c31c3e 100644 --- a/integration_tests/test_group_membership.py +++ b/integration_tests/test_group_membership.py @@ -2,16 +2,16 @@ import pytest -from pdc_api_client.client import get_changemaker -from pdc_api_client.models import PermissionGrantEntityType, PermissionGrantVerb -from pdc_api_client.permission_grants import ( +from pdc_api.client import get_changemaker +from pdc_api.models import PermissionGrantEntityType, PermissionGrantVerb +from pdc_api.permission_grants import ( ChangemakerPermissionGrant, PermissionGrantGranteeType, create_permission_grant, delete_permission_grant, ) -from pdc_api_client.seeding.pdc_entities import seed_changemaker -from pdc_api_client.transport import APISession +from pdc_api.seeding.pdc_entities import seed_changemaker +from pdc_api.transport import APISession def _can_manage(session: APISession, changemaker_id: int) -> bool: diff --git a/integration_tests/test_keycloak_admin.py b/integration_tests/test_keycloak_admin.py index 4cffee2..169c637 100644 --- a/integration_tests/test_keycloak_admin.py +++ b/integration_tests/test_keycloak_admin.py @@ -1,4 +1,4 @@ -from pdc_api_client.seeding.keycloak_admin import KeycloakOrganization, KeycloakUser +from pdc_api.seeding.keycloak_admin import KeycloakOrganization, KeycloakUser class TestEnsureOrganization: diff --git a/integration_tests/test_operations.py b/integration_tests/test_operations.py index 89d90a7..5c53252 100644 --- a/integration_tests/test_operations.py +++ b/integration_tests/test_operations.py @@ -5,7 +5,7 @@ import pytest import requests -from pdc_api_client.client import ( +from pdc_api.client import ( create_changemaker_field_value, create_changemaker_field_value_batch, create_changemaker_source, @@ -32,8 +32,8 @@ get_proposals, link_changemaker_to_proposal, ) -from pdc_api_client.errors import PDCNotFoundError, ProposalNotFoundError -from pdc_api_client.models import ( +from pdc_api.errors import PDCNotFoundError, ProposalNotFoundError +from pdc_api.models import ( BaseField, Changemaker, ChangemakerApplicationForm, @@ -53,7 +53,7 @@ Proposal, ProposalBundle, ) -from pdc_api_client.seeding.pdc_entities import ( +from pdc_api.seeding.pdc_entities import ( seed_application_form, seed_base_field, seed_changemaker, diff --git a/integration_tests/test_permission_grants.py b/integration_tests/test_permission_grants.py index 3908e04..4b29dbc 100644 --- a/integration_tests/test_permission_grants.py +++ b/integration_tests/test_permission_grants.py @@ -3,9 +3,9 @@ import pytest -from pdc_api_client.errors import PDCNotFoundError -from pdc_api_client.models import BaseFieldCategory -from pdc_api_client.permission_grants import ( +from pdc_api.errors import PDCNotFoundError +from pdc_api.models import BaseFieldCategory +from pdc_api.permission_grants import ( ChangemakerPermissionGrant, FunderPermissionGrant, PermissionGrantConditionRule, @@ -20,7 +20,7 @@ list_permission_grants, update_permission_grant, ) -from pdc_api_client.seeding.pdc_entities import seed_changemaker, seed_funder, seed_proposal +from pdc_api.seeding.pdc_entities import seed_changemaker, seed_funder, seed_proposal @pytest.fixture() diff --git a/integration_tests/test_preprocess_rules.py b/integration_tests/test_preprocess_rules.py index 4ef0353..cc15b16 100644 --- a/integration_tests/test_preprocess_rules.py +++ b/integration_tests/test_preprocess_rules.py @@ -1,6 +1,6 @@ -from pdc_api_client.client import get_changemaker, get_organization_by_keycloak_id -from pdc_api_client.models import Source -from pdc_api_client.seeding.pdc_entities import ( +from pdc_api.client import get_changemaker, get_organization_by_keycloak_id +from pdc_api.models import Source +from pdc_api.seeding.pdc_entities import ( seed_changemaker, seed_fiscal_sponsorship, seed_funder, diff --git a/integration_tests/test_seed.py b/integration_tests/test_seed.py index 652d1f7..581439d 100644 --- a/integration_tests/test_seed.py +++ b/integration_tests/test_seed.py @@ -1,5 +1,5 @@ -from pdc_api_client.client import get_changemaker_proposals -from pdc_api_client.seeding.pdc_entities import ( +from pdc_api.client import get_changemaker_proposals +from pdc_api.seeding.pdc_entities import ( SeededChangemakerWithProposals, SeededProposalBundle, seed_application_form, diff --git a/justfile b/justfile index 0ec6bce..797250c 100644 --- a/justfile +++ b/justfile @@ -94,20 +94,20 @@ check: lint typecheck test integration # Download the current PDC OpenAPI spec [group('codegen')] update-api-spec: - curl -fsSL https://api.philanthropydatacommons.org/openapi/api.json -o src/pdc_api_client/openapi.json - uv run python -c "import json; json.load(open('src/pdc_api_client/openapi.json'))" + curl -fsSL https://api.philanthropydatacommons.org/openapi/api.json -o src/pdc_api/openapi.json + uv run python -c "import json; json.load(open('src/pdc_api/openapi.json'))" -# Regenerate src/pdc_api_client/_generated.py from src/pdc_api_client/openapi.json +# Regenerate src/pdc_api/_generated.py from src/pdc_api/openapi.json [group('codegen')] codegen: - uv run python codegen/preprocess.py src/pdc_api_client/openapi.json codegen/openapi.preprocessed.json + uv run python codegen/preprocess.py src/pdc_api/openapi.json codegen/openapi.preprocessed.json uv run datamodel-codegen \ --input codegen/openapi.preprocessed.json --input-file-type openapi \ - --output src/pdc_api_client/_generated.py \ + --output src/pdc_api/_generated.py \ --output-model-type pydantic_v2.BaseModel \ - --base-class pdc_api_client._base.BaseSchema \ + --base-class pdc_api._base.BaseSchema \ --snake-case-field --use-annotated --use-standard-collections --use-union-operator \ --collapse-root-models --capitalise-enum-members --target-python-version 3.12 --disable-timestamp \ --formatters ruff-format ruff-check - uv run python codegen/postprocess.py src/pdc_api_client/_generated.py - uv run ruff format src/pdc_api_client/_generated.py + uv run python codegen/postprocess.py src/pdc_api/_generated.py + uv run ruff format src/pdc_api/_generated.py diff --git a/pyproject.toml b/pyproject.toml index d217d40..677c443 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "pdc-python-client" +name = "pdc-api" version = "0.3.0" description = "Python client for the Philanthropy Data Commons (PDC) API" readme = "README.md" @@ -30,9 +30,9 @@ testing = ["responses>=0.23"] seeding = ["faker>=26", "python-keycloak>=6"] [project.urls] -Repository = "https://github.com/PhilanthropyDataCommons/pdc-python-client" -Issues = "https://github.com/PhilanthropyDataCommons/pdc-python-client/issues" -Changelog = "https://github.com/PhilanthropyDataCommons/pdc-python-client/blob/main/CHANGELOG.md" +Repository = "https://github.com/PhilanthropyDataCommons/pdc-api-python" +Issues = "https://github.com/PhilanthropyDataCommons/pdc-api-python/issues" +Changelog = "https://github.com/PhilanthropyDataCommons/pdc-api-python/blob/main/CHANGELOG.md" "PDC API" = "https://api.philanthropydatacommons.org/" [dependency-groups] @@ -43,7 +43,7 @@ dev = [ { include-group = "typecheck" }, ] tests = [ - "pdc-python-client[seeding,testing]", + "pdc-api[seeding,testing]", "pytest-cov>=7", "pytest>=9", ] @@ -58,7 +58,7 @@ requires = ["uv_build>=0.12"] build-backend = "uv_build" [tool.uv.build-backend] -module-name = "pdc_api_client" +module-name = "pdc_api" source-include = [ "CHANGELOG.md", "codegen/*.py", @@ -67,18 +67,18 @@ source-include = [ "justfile", "tests/*.py", ] -wheel-exclude = ["pdc_api_client/openapi.json"] +wheel-exclude = ["pdc_api/openapi.json"] [tool.coverage.run] branch = true relative_files = true [tool.coverage.paths] -pdc_api_client = ["src/pdc_api_client/", "*/site-packages/pdc_api_client/"] +pdc_api = ["src/pdc_api/", "*/site-packages/pdc_api/"] [tool.pytest.ini_options] testpaths = ["tests"] -addopts = ["--cov=pdc_api_client", "--cov-report=term-missing"] +addopts = ["--cov=pdc_api", "--cov-report=term-missing"] [tool.mypy] files = ["src", "tests", "integration_tests"] @@ -99,7 +99,7 @@ extra-paths = ["tests"] [tool.ruff] line-length = 120 -extend-exclude = ["src/pdc_api_client/_generated.py"] +extend-exclude = ["src/pdc_api/_generated.py"] [tool.ruff.lint] extend-select = ["I", "S", "INT", "PLC0415"] diff --git a/src/pdc_api_client/__init__.py b/src/pdc_api/__init__.py similarity index 86% rename from src/pdc_api_client/__init__.py rename to src/pdc_api/__init__.py index 2a6c68e..1149545 100644 --- a/src/pdc_api_client/__init__.py +++ b/src/pdc_api/__init__.py @@ -1,4 +1,4 @@ -from pdc_api_client.errors import ( +from pdc_api.errors import ( ApplicationFormNotFoundError, ChangemakerFieldValueBatchNotFoundError, ChangemakerNotFoundError, @@ -14,8 +14,8 @@ ProposalNotFoundError, TokenRequestError, ) -from pdc_api_client.token import TokenProvider -from pdc_api_client.transport import APISession +from pdc_api.token import TokenProvider +from pdc_api.transport import APISession __all__ = [ "APISession", diff --git a/src/pdc_api_client/_base.py b/src/pdc_api/_base.py similarity index 100% rename from src/pdc_api_client/_base.py rename to src/pdc_api/_base.py diff --git a/src/pdc_api_client/_generated.py b/src/pdc_api/_generated.py similarity index 99% rename from src/pdc_api_client/_generated.py rename to src/pdc_api/_generated.py index ffcdae0..2488f04 100644 --- a/src/pdc_api_client/_generated.py +++ b/src/pdc_api/_generated.py @@ -1,4 +1,4 @@ -# Generated by `just codegen` from src/pdc_api_client/openapi.json. Do not edit. +# Generated by `just codegen` from src/pdc_api/openapi.json. Do not edit. # generated by datamodel-codegen: # filename: openapi.preprocessed.json @@ -10,7 +10,7 @@ from pydantic import AwareDatetime, ConfigDict, Field, RootModel -from pdc_api_client._base import BaseSchema +from pdc_api._base import BaseSchema class ApplicationFormFieldInputType(StrEnum): diff --git a/src/pdc_api_client/client.py b/src/pdc_api/client.py similarity index 99% rename from src/pdc_api_client/client.py rename to src/pdc_api/client.py index 4e6d089..58b96ad 100644 --- a/src/pdc_api_client/client.py +++ b/src/pdc_api/client.py @@ -5,8 +5,8 @@ import requests -from pdc_api_client import errors -from pdc_api_client.models import ( +from pdc_api import errors +from pdc_api.models import ( BaseField, Changemaker, ChangemakerApplicationForm, @@ -25,7 +25,7 @@ ProposalVersion, Source, ) -from pdc_api_client.transport import APISession +from pdc_api.transport import APISession def _iterate_pages( diff --git a/src/pdc_api_client/errors.py b/src/pdc_api/errors.py similarity index 100% rename from src/pdc_api_client/errors.py rename to src/pdc_api/errors.py diff --git a/src/pdc_api_client/models.py b/src/pdc_api/models.py similarity index 93% rename from src/pdc_api_client/models.py rename to src/pdc_api/models.py index f2fe4d8..c3d0b88 100644 --- a/src/pdc_api_client/models.py +++ b/src/pdc_api/models.py @@ -3,12 +3,12 @@ from pydantic import Field -from pdc_api_client import _generated -from pdc_api_client._base import BaseSchema -from pdc_api_client._generated import ( +from pdc_api import _generated +from pdc_api._base import BaseSchema +from pdc_api._generated import ( ApplicationForm as ChangemakerApplicationForm, ) -from pdc_api_client._generated import ( +from pdc_api._generated import ( ApplicationFormField, BaseField, BaseFieldCategory, @@ -37,10 +37,10 @@ ShallowChangemaker, Source, ) -from pdc_api_client._generated import ( +from pdc_api._generated import ( ApplicationFormFieldInputType as InputType, ) -from pdc_api_client._generated import ( +from pdc_api._generated import ( DataType as BaseFieldDataType, ) diff --git a/src/pdc_api_client/openapi.json b/src/pdc_api/openapi.json similarity index 100% rename from src/pdc_api_client/openapi.json rename to src/pdc_api/openapi.json diff --git a/src/pdc_api_client/permission_grants.py b/src/pdc_api/permission_grants.py similarity index 98% rename from src/pdc_api_client/permission_grants.py rename to src/pdc_api/permission_grants.py index fd9d722..f432b52 100644 --- a/src/pdc_api_client/permission_grants.py +++ b/src/pdc_api/permission_grants.py @@ -4,15 +4,15 @@ from pydantic import Field, TypeAdapter, field_validator, model_validator -from pdc_api_client.client import get_bundle_page -from pdc_api_client.models import ( +from pdc_api.client import get_bundle_page +from pdc_api.models import ( BaseFieldCategory, BaseSchema, PermissionGrantEntityType, PermissionGrantGranteeType, PermissionGrantVerb, ) -from pdc_api_client.transport import APISession +from pdc_api.transport import APISession _ENDPOINT = "permissionGrants" _DEFAULT_ENDPOINT = "defaultPermissionGrants" diff --git a/src/pdc_api_client/py.typed b/src/pdc_api/py.typed similarity index 100% rename from src/pdc_api_client/py.typed rename to src/pdc_api/py.typed diff --git a/src/pdc_api_client/seeding/__init__.py b/src/pdc_api/seeding/__init__.py similarity index 100% rename from src/pdc_api_client/seeding/__init__.py rename to src/pdc_api/seeding/__init__.py diff --git a/src/pdc_api_client/seeding/keycloak_admin.py b/src/pdc_api/seeding/keycloak_admin.py similarity index 100% rename from src/pdc_api_client/seeding/keycloak_admin.py rename to src/pdc_api/seeding/keycloak_admin.py diff --git a/src/pdc_api_client/seeding/pdc_entities.py b/src/pdc_api/seeding/pdc_entities.py similarity index 98% rename from src/pdc_api_client/seeding/pdc_entities.py rename to src/pdc_api/seeding/pdc_entities.py index 1429ed8..a5358ca 100644 --- a/src/pdc_api_client/seeding/pdc_entities.py +++ b/src/pdc_api/seeding/pdc_entities.py @@ -5,7 +5,7 @@ import requests from faker import Faker -from pdc_api_client.client import ( +from pdc_api.client import ( create_changemaker_field_value, create_changemaker_field_value_batch, create_changemaker_source, @@ -16,8 +16,8 @@ get_organization_by_keycloak_id, link_changemaker_to_proposal, ) -from pdc_api_client.errors import PDCNotFoundError -from pdc_api_client.models import ( +from pdc_api.errors import PDCNotFoundError +from pdc_api.models import ( BaseField, ChangemakerBundle, ChangemakerFieldValue, @@ -33,8 +33,8 @@ ShallowChangemaker, Source, ) -from pdc_api_client.seeding.keycloak_admin import KeycloakOrganization -from pdc_api_client.transport import APISession +from pdc_api.seeding.keycloak_admin import KeycloakOrganization +from pdc_api.transport import APISession fake = Faker() diff --git a/src/pdc_api_client/testing.py b/src/pdc_api/testing.py similarity index 99% rename from src/pdc_api_client/testing.py rename to src/pdc_api/testing.py index c00bc55..aa6be70 100644 --- a/src/pdc_api_client/testing.py +++ b/src/pdc_api/testing.py @@ -3,7 +3,7 @@ import responses -from pdc_api_client.client import PageableBundle +from pdc_api.client import PageableBundle CREATED_AT = "2026-01-01T00:00:00Z" CREATED_BY = "00000000-0000-0000-0000-000000000009" diff --git a/src/pdc_api_client/token.py b/src/pdc_api/token.py similarity index 97% rename from src/pdc_api_client/token.py rename to src/pdc_api/token.py index e3ef9cf..d2aec5d 100644 --- a/src/pdc_api_client/token.py +++ b/src/pdc_api/token.py @@ -3,7 +3,7 @@ import requests -from pdc_api_client.errors import PDCServiceError, TokenRequestError +from pdc_api.errors import PDCServiceError, TokenRequestError @runtime_checkable diff --git a/src/pdc_api_client/transport.py b/src/pdc_api/transport.py similarity index 97% rename from src/pdc_api_client/transport.py rename to src/pdc_api/transport.py index 7a3d578..d00af01 100644 --- a/src/pdc_api_client/transport.py +++ b/src/pdc_api/transport.py @@ -5,8 +5,8 @@ from requests.adapters import HTTPAdapter from urllib3.util import Retry -from pdc_api_client import errors -from pdc_api_client.token import TokenProvider +from pdc_api import errors +from pdc_api.token import TokenProvider _ERRORS_BY_STATUS = { 400: errors.PDCBadRequestError, diff --git a/tests/conftest.py b/tests/conftest.py index bb70f80..c626aa4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,8 +3,8 @@ import pytest import responses -from pdc_api_client import testing as pdc_testing -from pdc_api_client.transport import APISession +from pdc_api import testing as pdc_testing +from pdc_api.transport import APISession BASE_URL = "https://pdc.test/" diff --git a/tests/test_client.py b/tests/test_client.py index 54139fc..b6c94d4 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,7 +1,7 @@ import pytest -from pdc_api_client import errors -from pdc_api_client.client import ( +from pdc_api import errors +from pdc_api.client import ( _iterate_pages, get_base_fields, get_changemaker_field_value_batch, @@ -12,7 +12,7 @@ get_funders, get_initiatives, ) -from pdc_api_client.models import ( +from pdc_api.models import ( BaseFieldDataType, Changemaker, ChangemakerFieldValue, @@ -21,10 +21,10 @@ DataProvider, Funder, ) -from pdc_api_client.testing import ( +from pdc_api.testing import ( base_field_payload as _basefield, ) -from pdc_api_client.testing import ( +from pdc_api.testing import ( bundle, changemaker_field_value_batch_payload, changemaker_field_value_payload, diff --git a/tests/test_client_files.py b/tests/test_client_files.py index 37ddf5b..a514799 100644 --- a/tests/test_client_files.py +++ b/tests/test_client_files.py @@ -3,9 +3,9 @@ import pytest import responses -from pdc_api_client.client import upload_file_to_s3_presigned_url -from pdc_api_client.errors import PDCServiceError -from pdc_api_client.models import File, PresignedPost +from pdc_api.client import upload_file_to_s3_presigned_url +from pdc_api.errors import PDCServiceError +from pdc_api.models import File, PresignedPost PRESIGNED_URL = "https://s3.example.com/upload" diff --git a/tests/test_client_operations.py b/tests/test_client_operations.py index 95d9511..0b5357f 100644 --- a/tests/test_client_operations.py +++ b/tests/test_client_operations.py @@ -4,7 +4,7 @@ import pytest import responses -from pdc_api_client.client import ( +from pdc_api.client import ( create_changemaker_field_value, create_changemaker_field_value_batch, create_changemaker_source, @@ -23,14 +23,14 @@ get_proposal, link_changemaker_to_proposal, ) -from pdc_api_client.errors import ( +from pdc_api.errors import ( ApplicationFormNotFoundError, ChangemakerNotFoundError, FunderNotFoundError, PDCNotFoundError, ProposalNotFoundError, ) -from pdc_api_client.models import ( +from pdc_api.models import ( ChangemakerBundle, ChangemakerProposal, FunderCollaborativeMemberBundle, @@ -38,7 +38,7 @@ NewProposalVersion, Organization, ) -from pdc_api_client.testing import ( +from pdc_api.testing import ( application_form_payload, bundle, changemaker_field_value_batch_payload, diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index bc65b05..7674bd2 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -1,7 +1,7 @@ import pytest import responses -from pdc_api_client.seeding.keycloak_admin import KeycloakAdmin +from pdc_api.seeding.keycloak_admin import KeycloakAdmin KEYCLOAK_URL = "https://keycloak.test" ORGANIZATIONS_URL = f"{KEYCLOAK_URL}/admin/realms/pdc/organizations" diff --git a/tests/test_models.py b/tests/test_models.py index 363f03b..991d5a1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,6 +1,6 @@ -from pdc_api_client import _generated -from pdc_api_client.models import Funder, InitiativeFieldValue -from pdc_api_client.testing import funder_payload, initiative_field_value_payload +from pdc_api import _generated +from pdc_api.models import Funder, InitiativeFieldValue +from pdc_api.testing import funder_payload, initiative_field_value_payload class TestFunder: diff --git a/tests/test_permission_grants.py b/tests/test_permission_grants.py index 3ac5404..db60785 100644 --- a/tests/test_permission_grants.py +++ b/tests/test_permission_grants.py @@ -3,7 +3,7 @@ import pytest -from pdc_api_client.permission_grants import ( +from pdc_api.permission_grants import ( ChangemakerPermissionGrant, DefaultPermissionGrant, InitiativeFieldValuePermissionGrant, @@ -16,7 +16,7 @@ _grant_to_payload, list_permission_grants, ) -from pdc_api_client.testing import bundle +from pdc_api.testing import bundle ORG_UUID = UUID("00000000-0000-0000-0000-000000000001") USER_UUID = UUID("00000000-0000-0000-0000-000000000002") diff --git a/tests/test_token.py b/tests/test_token.py index 5043023..878576b 100644 --- a/tests/test_token.py +++ b/tests/test_token.py @@ -3,8 +3,8 @@ import pytest import responses -from pdc_api_client.errors import PDCServiceError, TokenRequestError -from pdc_api_client.token import KeycloakClientCredentialsProvider +from pdc_api.errors import PDCServiceError, TokenRequestError +from pdc_api.token import KeycloakClientCredentialsProvider SERVER = "https://kc.test" REALM = "pdc" diff --git a/tests/test_transport.py b/tests/test_transport.py index b8def22..4ef9429 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -3,7 +3,7 @@ import responses from conftest import BASE_URL, FakeTokenProvider -from pdc_api_client.errors import ( +from pdc_api.errors import ( PDCBadRequestError, PDCConflictError, PDCException, @@ -13,7 +13,7 @@ PDCUnauthorizedError, PDCUnprocessableEntityError, ) -from pdc_api_client.transport import APISession +from pdc_api.transport import APISession URL = f"{BASE_URL}test-endpoint" diff --git a/uv.lock b/uv.lock index 5c1e4cb..7461f3f 100644 --- a/uv.lock +++ b/uv.lock @@ -1045,7 +1045,7 @@ wheels = [ ] [[package]] -name = "pdc-python-client" +name = "pdc-api" version = "0.3.0" source = { editable = "." } dependencies = [ @@ -1067,7 +1067,7 @@ testing = [ dev = [ { name = "datamodel-code-generator", extra = ["ruff"] }, { name = "mypy" }, - { name = "pdc-python-client", extra = ["seeding", "testing"] }, + { name = "pdc-api", extra = ["seeding", "testing"] }, { name = "pyrefly" }, { name = "pytest" }, { name = "pytest-cov" }, @@ -1075,7 +1075,7 @@ dev = [ { name = "ty" }, ] tests = [ - { name = "pdc-python-client", extra = ["seeding", "testing"] }, + { name = "pdc-api", extra = ["seeding", "testing"] }, { name = "pytest" }, { name = "pytest-cov" }, ] @@ -1100,7 +1100,7 @@ provides-extras = ["testing", "seeding"] dev = [ { name = "datamodel-code-generator", extras = ["ruff"], specifier = ">=0.87" }, { name = "mypy", specifier = ">=2.4.1" }, - { name = "pdc-python-client", extras = ["seeding", "testing"] }, + { name = "pdc-api", extras = ["seeding", "testing"] }, { name = "pyrefly", specifier = ">=1.4.1" }, { name = "pytest", specifier = ">=9" }, { name = "pytest-cov", specifier = ">=7" }, @@ -1108,7 +1108,7 @@ dev = [ { name = "ty", specifier = ">=0.0.100" }, ] tests = [ - { name = "pdc-python-client", extras = ["seeding", "testing"] }, + { name = "pdc-api", extras = ["seeding", "testing"] }, { name = "pytest", specifier = ">=9" }, { name = "pytest-cov", specifier = ">=7" }, ]