Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/manual_regenerate_models.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow regenerates Pydantic models (src/apify_client/_models.py) from the OpenAPI spec.
# This workflow regenerates Pydantic models and TypedDicts (src/apify_client/_{models,typeddicts}_generated.py) from the OpenAPI spec.
#
# It can be triggered in two ways:
# 1. Automatically via workflow_dispatch from the apify-docs CI pipeline.
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
id: commit
uses: EndBug/add-and-commit@v10
with:
add: src/apify_client/_models.py
add: 'src/apify_client/_*_generated.py'
author_name: apify-service-account
author_email: apify-service-account@users.noreply.github.com
message: ${{ env.TITLE }}
Expand All @@ -130,9 +130,9 @@ jobs:
else
if [[ -n "$DOCS_PR_NUMBER" ]]; then
DOCS_PR_URL="https://github.com/apify/apify-docs/pull/${DOCS_PR_NUMBER}"
BODY="This PR updates the auto-generated Pydantic models based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL})."
BODY="This PR updates the auto-generated Pydantic models and TypedDicts based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL})."
else
BODY="This PR updates the auto-generated Pydantic models from the [published OpenAPI specification](https://docs.apify.com/api/openapi.json)."
BODY="This PR updates the auto-generated Pydantic models and TypedDicts from the [published OpenAPI specification](https://docs.apify.com/api/openapi.json)."
fi

PR_URL=$(gh pr create \
Expand Down
4 changes: 2 additions & 2 deletions .rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ uv run poe type-check # Run ty type checker
uv run poe unit-tests # Run unit tests
uv run poe check-docstrings # Verify async docstrings match sync
uv run poe fix-docstrings # Auto-fix async docstrings
uv run poe generate-models # Regenerate _models.py from live OpenAPI spec
uv run poe generate-models # Regenerate _models_generated.py and _typeddicts_generated.py from live OpenAPI spec
uv run poe generate-models-from-file <path> # Regenerate from a local OpenAPI spec file

# Run a single test
Expand Down Expand Up @@ -73,7 +73,7 @@ Docstrings are written on sync clients and **automatically copied** to async cli

### Data Models

`src/apify_client/_models.py` is **auto-generated** — do not edit it manually.
`src/apify_client/_models_generated.py` and `src/apify_client/_typeddicts_generated.py` are **auto-generated** — do not edit them manually. The hand-maintained `src/apify_client/_models.py` and `src/apify_client/_typeddicts.py` hold only shapes that are not exposed by the OpenAPI spec (or that need local logic); import generated types directly from the `_*_generated` modules.

- Generated by `datamodel-code-generator` from the OpenAPI spec at `https://docs.apify.com/api/openapi.json` (config in `pyproject.toml` under `[tool.datamodel-codegen]`, aliases in `datamodel_codegen_aliases.json`)
- After generation, `scripts/postprocess_generated_models.py` is run to apply additional fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/02_concepts/code/03_nested_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from apify_client import ApifyClientAsync
from apify_client._models import ActorJobStatus
from apify_client._models_generated import ActorJobStatus

TOKEN = 'MY-APIFY-TOKEN'

Expand Down
2 changes: 1 addition & 1 deletion docs/02_concepts/code/03_nested_sync.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from apify_client import ApifyClient
from apify_client._models import ActorJobStatus
Comment thread
vdusek marked this conversation as resolved.
from apify_client._models_generated import ActorJobStatus

TOKEN = 'MY-APIFY-TOKEN'

Expand Down
4 changes: 2 additions & 2 deletions docs/04_upgrading/upgrading_to_v3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ run.status
Models also use `populate_by_name=True`, which means you can use either the Python field name or the camelCase alias when **constructing** a model:

```python
from apify_client._models import Run
from apify_client._models_generated import Run

# Both work when constructing models
Run(default_dataset_id='abc') # Python field name
Expand Down Expand Up @@ -86,7 +86,7 @@ rq_client.add_request({
After (v3) — both forms are accepted:

```python
from apify_client._types import RequestInput
from apify_client._models import RequestInput

# Option 1: dict (still works)
rq_client.add_request({
Expand Down
22 changes: 18 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ indent-style = "space"
"**/docs/03_guides/code/05_custom_http_client_{async,sync}.py" = [
"ARG002", # Unused method argument
]
"src/apify_client/_models.py" = [
"src/apify_client/_*_generated.py" = [
"D", # Everything from the pydocstyle
"E501", # Line too long
"ERA001", # Commented-out code
Expand Down Expand Up @@ -210,7 +210,7 @@ context = 7
# https://koxudaxi.github.io/datamodel-code-generator/
[tool.datamodel-codegen]
input_file_type = "openapi"
output = "src/apify_client/_models.py"
output = "src/apify_client/_models_generated.py"
target_python_version = "3.11"
output_model_type = "pydantic_v2.BaseModel"
use_schema_description = true
Expand Down Expand Up @@ -272,8 +272,22 @@ shell = "./build_api_reference.sh && corepack enable && yarn && uv run yarn star
cwd = "website"

[tool.poe.tasks.generate-models]
shell = "uv run datamodel-codegen --url https://docs.apify.com/api/openapi.json && python scripts/postprocess_generated_models.py"
shell = """
uv run datamodel-codegen --url https://docs.apify.com/api/openapi.json \
&& uv run datamodel-codegen --url https://docs.apify.com/api/openapi.json \
--output src/apify_client/_typeddicts_generated.py \
--output-model-type typing.TypedDict \
--no-use-closed-typed-dict \
&& python scripts/postprocess_generated_models.py
"""

[tool.poe.tasks.generate-models-from-file]
shell = "uv run datamodel-codegen --input $input_file && python scripts/postprocess_generated_models.py"
shell = """
uv run datamodel-codegen --input $input_file \
&& uv run datamodel-codegen --input $input_file \
--output src/apify_client/_typeddicts_generated.py \
--output-model-type typing.TypedDict \
--no-use-closed-typed-dict \
&& python scripts/postprocess_generated_models.py
"""
args = [{ name = "input-file", positional = true, required = true }]
Loading