From f5f891072d79fcd1a1365adda6b878e746a4e5f8 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Fri, 27 Feb 2026 10:06:06 +0100 Subject: [PATCH 1/5] Populate by name to True --- pyproject.toml | 1 + src/apify_client/_models.py | 183 +++++++++++++++++++++++++++++++++++- 2 files changed, 183 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 157ead04..fcdf02ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -206,6 +206,7 @@ wrap_string_literal = true snake_case_field = true use_subclass_enum = true extra_fields = "allow" +allow_population_by_field_name = true aliases = "datamodel_codegen_aliases.json" formatters = ["ruff-check", "ruff-format"] diff --git a/src/apify_client/_models.py b/src/apify_client/_models.py index 26231768..fd55b903 100644 --- a/src/apify_client/_models.py +++ b/src/apify_client/_models.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: https://docs.apify.com/api/openapi.json -# timestamp: 2026-02-24T08:34:43+00:00 +# timestamp: 2026-02-27T09:05:36+00:00 from __future__ import annotations @@ -15,6 +15,7 @@ class PaginationResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) total: Annotated[int, Field(examples=[2], ge=0)] """ @@ -41,6 +42,7 @@ class PaginationResponse(BaseModel): class ActorStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) total_builds: Annotated[int | None, Field(alias='totalBuilds', examples=[9])] = None total_runs: Annotated[int | None, Field(alias='totalRuns', examples=[16])] = None @@ -57,6 +59,7 @@ class ActorStats(BaseModel): class ActorShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['br9CKmk457'])] created_at: Annotated[AwareDatetime, Field(alias='createdAt', examples=['2019-10-29T07:34:24.202Z'])] @@ -70,6 +73,7 @@ class ActorShort(BaseModel): class ListOfActors(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[ActorShort] @@ -77,6 +81,7 @@ class ListOfActors(PaginationResponse): class ListOfActorsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfActors @@ -84,6 +89,7 @@ class ListOfActorsResponse(BaseModel): class Error(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) type: Annotated[str, Field(examples=['run-failed'])] message: Annotated[str, Field(examples=['Actor run did not succeed (run ID: 55uatRrZib4xbZs, status: FAILED)'])] @@ -92,6 +98,7 @@ class Error(BaseModel): class ErrorResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) error: Error @@ -106,6 +113,7 @@ class VersionSourceType(StrEnum): class EnvVar(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: Annotated[str, Field(examples=['MY_ENV_VAR'])] value: Annotated[str, Field(examples=['my-value'])] @@ -120,6 +128,7 @@ class SourceCodeFileFormat(StrEnum): class SourceCodeFile(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) format: SourceCodeFileFormat content: Annotated[str, Field(examples=["console.log('This is the main.js file');"])] @@ -134,6 +143,7 @@ class SourceCodeFolder(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: Annotated[str, Field(examples=['src/utils'])] """ @@ -148,6 +158,7 @@ class SourceCodeFolder(BaseModel): class Version(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) version_number: Annotated[str, Field(alias='versionNumber', examples=['0.0'])] source_type: Annotated[VersionSourceType | None, Field(alias='sourceType')] = None @@ -174,6 +185,7 @@ class Version(BaseModel): class CommonActorPricingInfo(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) apify_margin_percentage: Annotated[float, Field(alias='apifyMarginPercentage')] """ @@ -202,6 +214,7 @@ class PricingModel(StrEnum): class ActorChargeEvent(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) event_price_usd: Annotated[float, Field(alias='eventPriceUsd')] event_title: Annotated[str, Field(alias='eventTitle')] @@ -211,6 +224,7 @@ class ActorChargeEvent(BaseModel): class PricingPerEvent(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_charge_events: Annotated[dict[str, ActorChargeEvent] | None, Field(alias='actorChargeEvents')] = None @@ -218,6 +232,7 @@ class PricingPerEvent(BaseModel): class PayPerEventActorPricingInfo(CommonActorPricingInfo): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) pricing_model: Annotated[Literal['PAY_PER_EVENT'], Field(alias='pricingModel')] pricing_per_event: Annotated[PricingPerEvent, Field(alias='pricingPerEvent')] @@ -227,6 +242,7 @@ class PayPerEventActorPricingInfo(CommonActorPricingInfo): class PricePerDatasetItemActorPricingInfo(CommonActorPricingInfo): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) pricing_model: Annotated[Literal['PRICE_PER_DATASET_ITEM'], Field(alias='pricingModel')] unit_name: Annotated[str, Field(alias='unitName')] @@ -239,6 +255,7 @@ class PricePerDatasetItemActorPricingInfo(CommonActorPricingInfo): class FlatPricePerMonthActorPricingInfo(CommonActorPricingInfo): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) pricing_model: Annotated[Literal['FLAT_PRICE_PER_MONTH'], Field(alias='pricingModel')] trial_minutes: Annotated[int, Field(alias='trialMinutes')] @@ -254,6 +271,7 @@ class FlatPricePerMonthActorPricingInfo(CommonActorPricingInfo): class FreeActorPricingInfo(CommonActorPricingInfo): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) pricing_model: Annotated[Literal['FREE'], Field(alias='pricingModel')] @@ -261,6 +279,7 @@ class FreeActorPricingInfo(CommonActorPricingInfo): class DefaultRunOptions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) build: Annotated[str, Field(examples=['latest'])] timeout_secs: Annotated[int | None, Field(alias='timeoutSecs', examples=[3600])] = None @@ -271,6 +290,7 @@ class DefaultRunOptions(BaseModel): class CreateActorRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: Annotated[str | None, Field(examples=['MyActor'])] = None description: Annotated[str | None, Field(examples=['My favourite actor!'])] = None @@ -304,6 +324,7 @@ class ActorPermissionLevel(StrEnum): class ExampleRunInput(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) body: Annotated[str, Field(examples=['{ "helloWorld": 123 }'])] content_type: Annotated[str, Field(alias='contentType', examples=['application/json; charset=utf-8'])] @@ -314,6 +335,7 @@ class TaggedBuildInfo(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) build_id: Annotated[str | None, Field(alias='buildId', examples=['z2EryhbfhgSyqj6Hn'])] = None """ @@ -334,6 +356,7 @@ class TaggedBuildInfo(BaseModel): class Actor(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['zdc3Pyhyz3m8vjDeM'])] user_id: Annotated[str, Field(alias='userId', examples=['wRsJZtadYvn4mBZmm'])] @@ -374,6 +397,7 @@ class ActorResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Actor @@ -381,6 +405,7 @@ class ActorResponse(BaseModel): class CreateOrUpdateVersionRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) version_number: Annotated[str | None, Field(alias='versionNumber', examples=['0.0'])] = None source_type: Annotated[VersionSourceType | None, Field(alias='sourceType')] = None @@ -407,6 +432,7 @@ class CreateOrUpdateVersionRequest(BaseModel): class BuildTag(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) build_id: Annotated[str, Field(alias='buildId')] @@ -414,6 +440,7 @@ class BuildTag(BaseModel): class UpdateActorRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: Annotated[str, Field(examples=['MyActor'])] description: Annotated[str | None, Field(examples=['My favourite actor!'])] = None @@ -486,6 +513,7 @@ class UpdateActorRequest(BaseModel): class ListOfVersions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) total: Annotated[int, Field(examples=[5])] items: list[Version] @@ -494,6 +522,7 @@ class ListOfVersions(BaseModel): class ListOfVersionsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfVersions @@ -501,6 +530,7 @@ class ListOfVersionsResponse(BaseModel): class VersionResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Version @@ -508,6 +538,7 @@ class VersionResponse(BaseModel): class ListOfEnvVars(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) total: Annotated[int, Field(examples=[5])] items: list[EnvVar] @@ -516,6 +547,7 @@ class ListOfEnvVars(BaseModel): class ListOfEnvVarsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfEnvVars @@ -523,6 +555,7 @@ class ListOfEnvVarsResponse(BaseModel): class EnvVarResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: EnvVar @@ -547,6 +580,7 @@ class WebhookEventType(StrEnum): class WebhookCondition(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_id: Annotated[str | None, Field(alias='actorId', examples=['hksJZtadYvn4mBuin'])] = None actor_task_id: Annotated[str | None, Field(alias='actorTaskId', examples=['asdLZtadYvn4mBZmm'])] = None @@ -564,6 +598,7 @@ class WebhookDispatchStatus(StrEnum): class ExampleWebhookDispatch(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) status: WebhookDispatchStatus finished_at: Annotated[AwareDatetime | None, Field(alias='finishedAt', examples=['2019-12-13T08:36:13.202Z'])] = ( @@ -574,6 +609,7 @@ class ExampleWebhookDispatch(BaseModel): class WebhookStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) total_dispatches: Annotated[int, Field(alias='totalDispatches', examples=[1])] @@ -581,6 +617,7 @@ class WebhookStats(BaseModel): class WebhookShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['YiKoxjkaS9gjGTqhF'])] created_at: Annotated[AwareDatetime, Field(alias='createdAt', examples=['2019-12-12T07:34:14.202Z'])] @@ -600,6 +637,7 @@ class WebhookShort(BaseModel): class ListOfWebhooks(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[WebhookShort] @@ -607,6 +645,7 @@ class ListOfWebhooks(PaginationResponse): class ListOfWebhooksResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfWebhooks @@ -639,6 +678,7 @@ class RunOrigin(StrEnum): class BuildsMeta(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) origin: RunOrigin client_ip: Annotated[str | None, Field(alias='clientIp', examples=['172.234.12.34'])] = None @@ -654,6 +694,7 @@ class BuildsMeta(BaseModel): class BuildShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['HG7ML7M8z78YcAPEB'])] act_id: Annotated[str | None, Field(alias='actId', examples=['janedoe~my-actor'])] = None @@ -669,6 +710,7 @@ class BuildShort(BaseModel): class ListOfBuilds(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[BuildShort] @@ -676,6 +718,7 @@ class ListOfBuilds(PaginationResponse): class ListOfBuildsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfBuilds @@ -683,6 +726,7 @@ class ListOfBuildsResponse(BaseModel): class BuildStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) duration_millis: Annotated[int | None, Field(alias='durationMillis', examples=[1000])] = None run_time_secs: Annotated[float | None, Field(alias='runTimeSecs', examples=[45.718])] = None @@ -692,6 +736,7 @@ class BuildStats(BaseModel): class BuildOptions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) use_cache: Annotated[bool | None, Field(alias='useCache', examples=[False])] = None beta_packages: Annotated[bool | None, Field(alias='betaPackages', examples=[False])] = None @@ -702,6 +747,7 @@ class BuildOptions(BaseModel): class BuildUsage(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_compute_units: Annotated[float | None, Field(alias='ACTOR_COMPUTE_UNITS', examples=[0.08])] = None @@ -709,6 +755,7 @@ class BuildUsage(BaseModel): class Storages(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) dataset: dict[str, Any] | None = None """ @@ -721,6 +768,7 @@ class ActorDefinition(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_specification: Annotated[Literal[1], Field(alias='actorSpecification')] = 1 """ @@ -784,6 +832,7 @@ class ActorDefinition(BaseModel): class Build(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['HG7ML7M8z78YcAPEB'])] act_id: Annotated[str, Field(alias='actId', examples=['janedoe~my-actor'])] @@ -812,6 +861,7 @@ class BuildResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Build @@ -819,6 +869,7 @@ class BuildResponse(BaseModel): class RunMeta(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) origin: RunOrigin client_ip: Annotated[str | None, Field(alias='clientIp')] = None @@ -842,6 +893,7 @@ class RunMeta(BaseModel): class RunShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['HG7ML7M8z78YcAPEB'])] act_id: Annotated[str, Field(alias='actId', examples=['HDSasDasz78YcAPEB'])] @@ -863,6 +915,7 @@ class RunShort(BaseModel): class ListOfRuns(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[RunShort] @@ -870,6 +923,7 @@ class ListOfRuns(PaginationResponse): class ListOfRunsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfRuns @@ -877,6 +931,7 @@ class ListOfRunsResponse(BaseModel): class RunStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) input_body_len: Annotated[int | None, Field(alias='inputBodyLen', examples=[240], ge=0)] = None migration_count: Annotated[int | None, Field(alias='migrationCount', examples=[0], ge=0)] = None @@ -900,6 +955,7 @@ class RunStats(BaseModel): class RunOptions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) build: Annotated[str, Field(examples=['latest'])] timeout_secs: Annotated[int, Field(alias='timeoutSecs', examples=[300], ge=0)] @@ -921,6 +977,7 @@ class GeneralAccess(StrEnum): class RunUsage(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_compute_units: Annotated[float | None, Field(alias='ACTOR_COMPUTE_UNITS', examples=[3])] = None dataset_reads: Annotated[int | None, Field(alias='DATASET_READS', examples=[4])] = None @@ -947,6 +1004,7 @@ class RunUsageUsd(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_compute_units: Annotated[float | None, Field(alias='ACTOR_COMPUTE_UNITS', examples=[0.0003])] = None dataset_reads: Annotated[float | None, Field(alias='DATASET_READS', examples=[0.0001])] = None @@ -973,6 +1031,7 @@ class Metamorph(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) created_at: Annotated[AwareDatetime, Field(alias='createdAt', examples=['2019-11-30T07:39:24.202Z'])] """ @@ -997,6 +1056,7 @@ class Run(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['HG7ML7M8z78YcAPEB'])] """ @@ -1129,6 +1189,7 @@ class Run(BaseModel): class RunResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Run @@ -1136,6 +1197,7 @@ class RunResponse(BaseModel): class TaskStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) total_runs: Annotated[int | None, Field(alias='totalRuns', examples=[15])] = None @@ -1143,6 +1205,7 @@ class TaskStats(BaseModel): class TaskShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['zdc3Pyhyz3m8vjDeM'])] user_id: Annotated[str, Field(alias='userId', examples=['wRsJZtadYvn4mBZmm'])] @@ -1159,6 +1222,7 @@ class TaskShort(BaseModel): class ListOfTasks(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[TaskShort] @@ -1166,6 +1230,7 @@ class ListOfTasks(PaginationResponse): class ListOfTasksResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfTasks @@ -1173,6 +1238,7 @@ class ListOfTasksResponse(BaseModel): class TaskOptions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) build: Annotated[str | None, Field(examples=['latest'])] = None timeout_secs: Annotated[int | None, Field(alias='timeoutSecs', examples=[300])] = None @@ -1188,12 +1254,14 @@ class TaskInput(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) class CreateTaskRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) act_id: Annotated[str, Field(alias='actId', examples=['asADASadYvn4mBZmm'])] name: Annotated[str, Field(examples=['my-task'])] @@ -1204,6 +1272,7 @@ class CreateTaskRequest(BaseModel): class Task(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['zdc3Pyhyz3m8vjDeM'])] user_id: Annotated[str, Field(alias='userId', examples=['wRsJZtadYvn4mBZmm'])] @@ -1224,6 +1293,7 @@ class TaskResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Task @@ -1231,6 +1301,7 @@ class TaskResponse(BaseModel): class UpdateTaskRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['ZxLNxrRaZrSjuhT9y'])] user_id: Annotated[str, Field(alias='userId', examples=['BPWZBd7Z9c746JAnF'])] @@ -1248,6 +1319,7 @@ class UpdateTaskRequest(BaseModel): class Webhook(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['YiKoxjkaS9gjGTqhF'])] created_at: Annotated[AwareDatetime, Field(alias='createdAt', examples=['2019-12-12T07:34:14.202Z'])] @@ -1274,6 +1346,7 @@ class Webhook(BaseModel): class UpdateRunRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) run_id: Annotated[str | None, Field(alias='runId', examples=['3KH8gEpp4d8uQSe8T'])] = None status_message: Annotated[str | None, Field(alias='statusMessage', examples=['Actor has finished'])] = None @@ -1284,6 +1357,7 @@ class UpdateRunRequest(BaseModel): class ChargeRunRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) event_name: Annotated[str, Field(alias='eventName', examples=['ANALYZE_PAGE'])] count: Annotated[int, Field(examples=[1])] @@ -1297,6 +1371,7 @@ class StorageOwnership(StrEnum): class KeyValueStoreStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) read_count: Annotated[int, Field(alias='readCount', examples=[9])] write_count: Annotated[int, Field(alias='writeCount', examples=[3])] @@ -1308,6 +1383,7 @@ class KeyValueStoreStats(BaseModel): class KeyValueStore(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['WkzbQMuFYuamGv3YF'])] name: Annotated[str | None, Field(examples=['d7b9MDYsbtX5L7XAj'])] = None @@ -1343,6 +1419,7 @@ class KeyValueStore(BaseModel): class ListOfKeyValueStores(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[KeyValueStore] @@ -1350,6 +1427,7 @@ class ListOfKeyValueStores(PaginationResponse): class ListOfKeyValueStoresResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfKeyValueStores @@ -1359,6 +1437,7 @@ class KeyValueStoreResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: KeyValueStore @@ -1366,6 +1445,7 @@ class KeyValueStoreResponse(BaseModel): class UpdateStoreRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: str | None = None general_access: Annotated[GeneralAccess | None, Field(alias='generalAccess')] = None @@ -1374,6 +1454,7 @@ class UpdateStoreRequest(BaseModel): class KeyValueStoreKey(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) key: Annotated[str, Field(examples=['second-key'])] size: Annotated[int, Field(examples=[36])] @@ -1392,6 +1473,7 @@ class KeyValueStoreKey(BaseModel): class ListOfKeys(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[KeyValueStoreKey] count: Annotated[int, Field(examples=[2])] @@ -1404,6 +1486,7 @@ class ListOfKeys(BaseModel): class ListOfKeysResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfKeys @@ -1416,6 +1499,7 @@ class RecordResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) @@ -1427,12 +1511,14 @@ class PutRecordRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) class DatasetListItem(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['WkzbQMuFYuamGv3YF'])] name: Annotated[str, Field(examples=['d7b9MDYsbtX5L7XAj'])] @@ -1449,6 +1535,7 @@ class DatasetListItem(BaseModel): class ListOfDatasets(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[DatasetListItem] @@ -1456,6 +1543,7 @@ class ListOfDatasets(PaginationResponse): class ListOfDatasetsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfDatasets @@ -1463,6 +1551,7 @@ class ListOfDatasetsResponse(BaseModel): class DatasetStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) read_count: Annotated[int, Field(alias='readCount', examples=[22])] write_count: Annotated[int, Field(alias='writeCount', examples=[3])] @@ -1472,6 +1561,7 @@ class DatasetStats(BaseModel): class Dataset(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['WkzbQMuFYuamGv3YF'])] name: Annotated[str | None, Field(examples=['d7b9MDYsbtX5L7XAj'])] = None @@ -1535,6 +1625,7 @@ class DatasetResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Dataset @@ -1542,6 +1633,7 @@ class DatasetResponse(BaseModel): class UpdateDatasetRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: str | None = None general_access: Annotated[GeneralAccess | None, Field(alias='generalAccess')] = None @@ -1555,12 +1647,14 @@ class PutItemsRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) class ValidationError(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) instance_path: Annotated[str | None, Field(alias='instancePath')] = None """ @@ -1587,6 +1681,7 @@ class ValidationError(BaseModel): class InvalidItem(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) item_position: Annotated[int | None, Field(alias='itemPosition', examples=[2])] = None """ @@ -1601,6 +1696,7 @@ class InvalidItem(BaseModel): class SchemaValidationErrorData(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) invalid_items: Annotated[list[InvalidItem], Field(alias='invalidItems')] """ @@ -1611,6 +1707,7 @@ class SchemaValidationErrorData(BaseModel): class DatasetSchemaValidationError(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) type: Annotated[str | None, Field(examples=['schema-validation-error'])] = None """ @@ -1626,6 +1723,7 @@ class DatasetSchemaValidationError(BaseModel): class PutItemResponseError(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) error: DatasetSchemaValidationError @@ -1633,6 +1731,7 @@ class PutItemResponseError(BaseModel): class DatasetFieldStatistics(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) min: float | None = None """ @@ -1655,6 +1754,7 @@ class DatasetFieldStatistics(BaseModel): class DatasetStatistics(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) field_statistics: Annotated[dict[str, Any] | None, Field(alias='fieldStatistics')] = None """ @@ -1665,6 +1765,7 @@ class DatasetStatistics(BaseModel): class DatasetStatisticsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: DatasetStatistics @@ -1674,6 +1775,7 @@ class RequestQueueShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['WkzbQMuFYuamGv3YF'])] """ @@ -1738,6 +1840,7 @@ class ListOfRequestQueues(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[RequestQueueShort] """ @@ -1750,6 +1853,7 @@ class ListOfRequestQueuesResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfRequestQueues @@ -1759,6 +1863,7 @@ class RequestQueueStats(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) delete_count: Annotated[int | None, Field(alias='deleteCount', examples=[0])] = None """ @@ -1787,6 +1892,7 @@ class RequestQueue(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['WkzbQMuFYuamGv3YF'])] """ @@ -1843,6 +1949,7 @@ class RequestQueueResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: RequestQueue @@ -1852,6 +1959,7 @@ class UpdateRequestQueueRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: str | None = None """ @@ -1865,6 +1973,7 @@ class RequestDraft(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str | None, Field(examples=['sbJ7klsdf7ujN9l'])] = None """ @@ -1889,6 +1998,7 @@ class AddedRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) request_id: Annotated[str, Field(alias='requestId', examples=['sbJ7klsdf7ujN9l'])] """ @@ -1913,6 +2023,7 @@ class BatchAddResult(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) processed_requests: Annotated[list[AddedRequest], Field(alias='processedRequests')] """ @@ -1929,6 +2040,7 @@ class BatchAddResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: BatchAddResult @@ -1938,6 +2050,7 @@ class DeletedRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) unique_key: Annotated[str, Field(alias='uniqueKey', examples=['GET|60d83e70|e3b0c442|https://apify.com'])] """ @@ -1954,6 +2067,7 @@ class BatchDeleteResult(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) processed_requests: Annotated[list[DeletedRequest], Field(alias='processedRequests')] """ @@ -1970,6 +2084,7 @@ class BatchDeleteResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: BatchDeleteResult @@ -1979,6 +2094,7 @@ class UnlockRequestsResult(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) unlocked_count: Annotated[int, Field(alias='unlockedCount', examples=[10])] """ @@ -1991,6 +2107,7 @@ class UnlockRequestsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: UnlockRequestsResult @@ -2000,6 +2117,7 @@ class RequestUserData(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) label: Annotated[str | None, Field(examples=['DETAIL'])] = None """ @@ -2016,6 +2134,7 @@ class Request(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['dnjkDMKLmdlkmlkmld'])] """ @@ -2069,6 +2188,7 @@ class ListOfRequests(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[Request] """ @@ -2093,6 +2213,7 @@ class ListOfRequestsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfRequests @@ -2102,6 +2223,7 @@ class RequestRegistration(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) request_id: Annotated[str, Field(alias='requestId', examples=['YiKoxjkaS9gjGTqhF'])] """ @@ -2122,6 +2244,7 @@ class AddRequestResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: RequestRegistration @@ -2131,6 +2254,7 @@ class RequestResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Request @@ -2140,6 +2264,7 @@ class UpdateRequestResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: RequestRegistration @@ -2149,6 +2274,7 @@ class HeadRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['8OamqXBCpPHxyH9'])] """ @@ -2177,6 +2303,7 @@ class RequestQueueHead(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) limit: Annotated[int, Field(examples=[1000])] """ @@ -2201,6 +2328,7 @@ class HeadResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: RequestQueueHead @@ -2210,6 +2338,7 @@ class LockedHeadRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['8OamqXBCpPHxyH9'])] """ @@ -2242,6 +2371,7 @@ class LockedRequestQueueHead(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) limit: Annotated[int, Field(examples=[1000])] """ @@ -2278,6 +2408,7 @@ class HeadAndLockResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: LockedRequestQueueHead @@ -2287,6 +2418,7 @@ class RequestLockInfo(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) lock_expires_at: Annotated[AwareDatetime, Field(alias='lockExpiresAt', examples=['2022-01-01T00:00:00.000Z'])] """ @@ -2299,6 +2431,7 @@ class ProlongRequestLockResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: RequestLockInfo @@ -2306,6 +2439,7 @@ class ProlongRequestLockResponse(BaseModel): class WebhookCreate(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) is_ad_hoc: Annotated[bool | None, Field(alias='isAdHoc', examples=[False])] = None event_types: Annotated[list[WebhookEventType], Field(alias='eventTypes', examples=[['ACTOR.RUN.SUCCEEDED']])] @@ -2329,6 +2463,7 @@ class WebhookResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Webhook @@ -2336,6 +2471,7 @@ class WebhookResponse(BaseModel): class WebhookUpdate(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) is_ad_hoc: Annotated[bool | None, Field(alias='isAdHoc', examples=[False])] = None event_types: Annotated[ @@ -2358,6 +2494,7 @@ class WebhookUpdate(BaseModel): class EventData(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actor_id: Annotated[str, Field(alias='actorId', examples=['vvE7iMKuMc5qTHHsR'])] actor_run_id: Annotated[str, Field(alias='actorRunId', examples=['JgwXN9BdwxGcu9MMF'])] @@ -2366,6 +2503,7 @@ class EventData(BaseModel): class Call(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) started_at: Annotated[AwareDatetime | None, Field(alias='startedAt', examples=['2019-12-12T07:34:14.202Z'])] = None finished_at: Annotated[AwareDatetime | None, Field(alias='finishedAt', examples=['2019-12-12T07:34:14.202Z'])] = ( @@ -2379,6 +2517,7 @@ class Call(BaseModel): class WebhookDispatch(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['asdLZtadYvn4mBZmm'])] user_id: Annotated[str, Field(alias='userId', examples=['wRsJZtadYvn4mBZmm'])] @@ -2393,6 +2532,7 @@ class WebhookDispatch(BaseModel): class TestWebhookResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: WebhookDispatch @@ -2400,6 +2540,7 @@ class TestWebhookResponse(BaseModel): class ListOfWebhookDispatches(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[WebhookDispatch] @@ -2407,6 +2548,7 @@ class ListOfWebhookDispatches(PaginationResponse): class WebhookDispatchList(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfWebhookDispatches | None = None @@ -2414,6 +2556,7 @@ class WebhookDispatchList(BaseModel): class WebhookDispatchResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: WebhookDispatch @@ -2428,6 +2571,7 @@ class ScheduleActionType(StrEnum): class ScheduleAction(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['ZReCs7hkdieq8ZUki'])] type: ScheduleActionType @@ -2437,6 +2581,7 @@ class ScheduleAction(BaseModel): class ScheduleShort(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['asdLZtadYvn4mBZmm'])] user_id: Annotated[str, Field(alias='userId', examples=['wRsJZtadYvn4mBZmm'])] @@ -2455,6 +2600,7 @@ class ScheduleShort(BaseModel): class ListOfSchedules(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[ScheduleShort] @@ -2462,6 +2608,7 @@ class ListOfSchedules(PaginationResponse): class ListOfSchedulesResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfSchedules @@ -2469,6 +2616,7 @@ class ListOfSchedulesResponse(BaseModel): class ScheduleActionsRunInput(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) body: Annotated[str | None, Field(examples=['{\\n "foo": "actor"\\n}'])] = None content_type: Annotated[str | None, Field(alias='contentType', examples=['application/json; charset=utf-8'])] = None @@ -2477,6 +2625,7 @@ class ScheduleActionsRunInput(BaseModel): class ScheduleActionsRunOptions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) build: Annotated[str | None, Field(examples=['latest'])] = None timeout_secs: Annotated[int | None, Field(alias='timeoutSecs', examples=[60])] = None @@ -2487,6 +2636,7 @@ class ScheduleActionsRunOptions(BaseModel): class ScheduleCreateActions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) type: ScheduleActionType actor_id: Annotated[str, Field(alias='actorId', examples=['jF8GGEvbEg4Au3NLA'])] @@ -2497,6 +2647,7 @@ class ScheduleCreateActions(BaseModel): class ScheduleCreate(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: Annotated[str | None, Field(examples=['my-schedule'])] = None is_enabled: Annotated[bool | None, Field(alias='isEnabled', examples=[True])] = None @@ -2510,6 +2661,7 @@ class ScheduleCreate(BaseModel): class ScheduleActions(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['c6KfSgoQzFhMk3etc'])] type: ScheduleActionType @@ -2521,6 +2673,7 @@ class ScheduleActions(BaseModel): class Schedule(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['asdLZtadYvn4mBZmm'])] user_id: Annotated[str, Field(alias='userId', examples=['wRsJZtadYvn4mBZmm'])] @@ -2540,6 +2693,7 @@ class Schedule(BaseModel): class ScheduleResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: Schedule @@ -2547,6 +2701,7 @@ class ScheduleResponse(BaseModel): class ScheduleInvoked(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) message: Annotated[str, Field(examples=['Schedule invoked'])] level: Annotated[str, Field(examples=['INFO'])] @@ -2556,6 +2711,7 @@ class ScheduleInvoked(BaseModel): class ScheduleLogResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: list[ScheduleInvoked] @@ -2563,6 +2719,7 @@ class ScheduleLogResponse(BaseModel): class CurrentPricingInfo(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) pricing_model: Annotated[str, Field(alias='pricingModel', examples=['FREE'])] @@ -2570,6 +2727,7 @@ class CurrentPricingInfo(BaseModel): class StoreListActor(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['zdc3Pyhyz3m8vjDeM'])] title: Annotated[str, Field(examples=['My Public Actor'])] @@ -2597,6 +2755,7 @@ class StoreListActor(BaseModel): class ListOfStoreActors(PaginationResponse): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) items: list[StoreListActor] @@ -2604,6 +2763,7 @@ class ListOfStoreActors(PaginationResponse): class ListOfActorsInStoreResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: ListOfStoreActors @@ -2611,6 +2771,7 @@ class ListOfActorsInStoreResponse(BaseModel): class Profile(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) bio: Annotated[str | None, Field(examples=['I started web scraping in 1985 using Altair BASIC.'])] = None name: Annotated[str | None, Field(examples=['Jane Doe'])] = None @@ -2625,6 +2786,7 @@ class Profile(BaseModel): class UserPublicInfo(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) username: Annotated[str, Field(examples=['d7b9MDYsbtX5L7XAj'])] profile: Profile @@ -2633,6 +2795,7 @@ class UserPublicInfo(BaseModel): class PublicUserDataResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: UserPublicInfo @@ -2640,6 +2803,7 @@ class PublicUserDataResponse(BaseModel): class ProxyGroup(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) name: Annotated[str, Field(examples=['Group1'])] description: Annotated[str, Field(examples=['Group1 description'])] @@ -2649,6 +2813,7 @@ class ProxyGroup(BaseModel): class Proxy(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) password: Annotated[str, Field(examples=['ad78knd9Jkjd86'])] groups: list[ProxyGroup] @@ -2657,6 +2822,7 @@ class Proxy(BaseModel): class Plan(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['Personal'])] description: Annotated[str, Field(examples=['Cost-effective plan for freelancers, developers and students.'])] @@ -2696,6 +2862,7 @@ class Plan(BaseModel): class EffectivePlatformFeature(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) is_enabled: Annotated[bool, Field(alias='isEnabled', examples=[True])] disabled_reason: Annotated[ @@ -2717,6 +2884,7 @@ class EffectivePlatformFeature(BaseModel): class EffectivePlatformFeatures(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) actors: Annotated[EffectivePlatformFeature, Field(alias='ACTORS')] storage: Annotated[EffectivePlatformFeature, Field(alias='STORAGE')] @@ -2733,6 +2901,7 @@ class EffectivePlatformFeatures(BaseModel): class UserPrivateInfo(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) id: Annotated[str, Field(examples=['YiKoxjkaS9gjGTqhF'])] username: Annotated[str, Field(examples=['myusername'])] @@ -2748,6 +2917,7 @@ class UserPrivateInfo(BaseModel): class PrivateUserDataResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: UserPrivateInfo @@ -2755,6 +2925,7 @@ class PrivateUserDataResponse(BaseModel): class UsageCycle(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) start_at: Annotated[AwareDatetime, Field(alias='startAt', examples=['2022-10-02T00:00:00.000Z'])] end_at: Annotated[AwareDatetime, Field(alias='endAt', examples=['2022-11-01T23:59:59.999Z'])] @@ -2763,6 +2934,7 @@ class UsageCycle(BaseModel): class PriceTiers(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) quantity_above: Annotated[float, Field(alias='quantityAbove', examples=[0])] discount_percent: Annotated[float, Field(alias='discountPercent', examples=[100])] @@ -2774,6 +2946,7 @@ class PriceTiers(BaseModel): class UsageItem(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) quantity: Annotated[float, Field(examples=[2.784475])] base_amount_usd: Annotated[float, Field(alias='baseAmountUsd', examples=[0.69611875])] @@ -2787,6 +2960,7 @@ class UsageItem(BaseModel): class DailyServiceUsages(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) date: Annotated[str, Field(examples=['2022-10-02T00:00:00.000Z'])] service_usage: Annotated[dict[str, UsageItem], Field(alias='serviceUsage')] @@ -2796,6 +2970,7 @@ class DailyServiceUsages(BaseModel): class MonthlyUsage(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) usage_cycle: Annotated[UsageCycle, Field(alias='usageCycle')] monthly_service_usage: Annotated[dict[str, UsageItem], Field(alias='monthlyServiceUsage')] @@ -2811,6 +2986,7 @@ class MonthlyUsage(BaseModel): class MonthlyUsageResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: MonthlyUsage @@ -2818,6 +2994,7 @@ class MonthlyUsageResponse(BaseModel): class Limits(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) max_monthly_usage_usd: Annotated[float, Field(alias='maxMonthlyUsageUsd', examples=[300])] max_monthly_actor_compute_units: Annotated[float, Field(alias='maxMonthlyActorComputeUnits', examples=[1000])] @@ -2839,6 +3016,7 @@ class Limits(BaseModel): class Current(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) monthly_usage_usd: Annotated[float, Field(alias='monthlyUsageUsd', examples=[43])] monthly_actor_compute_units: Annotated[float, Field(alias='monthlyActorComputeUnits', examples=[500.784475])] @@ -2857,6 +3035,7 @@ class Current(BaseModel): class AccountLimits(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) monthly_usage_cycle: Annotated[UsageCycle, Field(alias='monthlyUsageCycle')] limits: Limits @@ -2866,6 +3045,7 @@ class AccountLimits(BaseModel): class LimitsResponse(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) data: AccountLimits @@ -2873,6 +3053,7 @@ class LimitsResponse(BaseModel): class UpdateLimitsRequest(BaseModel): model_config = ConfigDict( extra='allow', + populate_by_name=True, ) max_monthly_usage_usd: Annotated[float | None, Field(alias='maxMonthlyUsageUsd', examples=[300])] = None """ From 0c9988fe9d6212e3541120e992d43e811f87a035 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Fri, 27 Feb 2026 10:07:04 +0100 Subject: [PATCH 2/5] Code adjustment --- src/apify_client/_consts.py | 1 - src/apify_client/_representations.py | 302 ------------------ .../_resource_clients/_resource_client.py | 55 +++- src/apify_client/_resource_clients/actor.py | 128 ++++---- .../_resource_clients/actor_collection.py | 98 +++--- .../_resource_clients/actor_env_var.py | 31 +- .../actor_env_var_collection.py | 18 +- .../_resource_clients/actor_version.py | 44 +-- .../actor_version_collection.py | 36 ++- src/apify_client/_resource_clients/dataset.py | 17 +- .../_resource_clients/dataset_collection.py | 5 +- .../_resource_clients/key_value_store.py | 17 +- .../key_value_store_collection.py | 5 +- .../_resource_clients/request_queue.py | 18 +- src/apify_client/_resource_clients/run.py | 27 +- .../_resource_clients/run_collection.py | 5 +- .../_resource_clients/schedule.py | 32 +- .../_resource_clients/schedule_collection.py | 29 +- src/apify_client/_resource_clients/task.py | 83 ++--- .../_resource_clients/task_collection.py | 80 +++-- src/apify_client/_resource_clients/user.py | 6 +- src/apify_client/_resource_clients/webhook.py | 49 +-- .../_resource_clients/webhook_collection.py | 54 ++-- src/apify_client/_utils.py | 82 +---- tests/unit/test_utils.py | 47 +-- 25 files changed, 454 insertions(+), 815 deletions(-) delete mode 100644 src/apify_client/_representations.py diff --git a/src/apify_client/_consts.py b/src/apify_client/_consts.py index 32d32909..1b25b197 100644 --- a/src/apify_client/_consts.py +++ b/src/apify_client/_consts.py @@ -25,7 +25,6 @@ DEFAULT_MIN_DELAY_BETWEEN_RETRIES = timedelta(milliseconds=500) """Default minimum delay between retries.""" - DEFAULT_WAIT_FOR_FINISH = timedelta(seconds=999999) """Default maximum wait time for job completion (effectively infinite).""" diff --git a/src/apify_client/_representations.py b/src/apify_client/_representations.py deleted file mode 100644 index a0a24423..00000000 --- a/src/apify_client/_representations.py +++ /dev/null @@ -1,302 +0,0 @@ -"""Helper functions for building API request representations. - -This module provides utilities for constructing dictionary representations of API resources. These representations -are used when creating or updating resources via the Apify API. -""" - -from __future__ import annotations - -from typing import TYPE_CHECKING, Any - -from apify_client._utils import enum_to_value, to_seconds - -if TYPE_CHECKING: - from datetime import timedelta - - from apify_client._models import ActorPermissionLevel, VersionSourceType, WebhookEventType - - -def build_actor_standby_dict( - *, - is_enabled: bool | None = None, - desired_requests_per_actor_run: int | None = None, - max_requests_per_actor_run: int | None = None, - idle_timeout: timedelta | None = None, - build: str | None = None, - memory_mbytes: int | None = None, -) -> dict: - """Build Actor standby configuration dictionary.""" - return { - 'isEnabled': is_enabled, - 'desiredRequestsPerActorRun': desired_requests_per_actor_run, - 'maxRequestsPerActorRun': max_requests_per_actor_run, - 'idleTimeoutSecs': to_seconds(idle_timeout, as_int=True), - 'build': build, - 'memoryMbytes': memory_mbytes, - } - - -def build_default_run_options_dict( - *, - build: str | None = None, - max_items: int | None = None, - memory_mbytes: int | None = None, - timeout: timedelta | None = None, - restart_on_error: bool | None = None, - force_permission_level: ActorPermissionLevel | None = None, -) -> dict: - """Build default run options dictionary for Actor.""" - return { - 'build': build, - 'maxItems': max_items, - 'memoryMbytes': memory_mbytes, - 'timeoutSecs': to_seconds(timeout, as_int=True), - 'restartOnError': restart_on_error, - 'forcePermissionLevel': force_permission_level, - } - - -def build_task_options_dict( - *, - build: str | None = None, - max_items: int | None = None, - memory_mbytes: int | None = None, - timeout: timedelta | None = None, - restart_on_error: bool | None = None, -) -> dict: - """Build task options dictionary.""" - return { - 'build': build, - 'maxItems': max_items, - 'memoryMbytes': memory_mbytes, - 'timeoutSecs': to_seconds(timeout, as_int=True), - 'restartOnError': restart_on_error, - } - - -def build_example_run_input_dict( - *, - body: Any = None, - content_type: str | None = None, -) -> dict: - """Build example run input dictionary for Actor.""" - return { - 'body': body, - 'contentType': content_type, - } - - -def build_webhook_condition_dict( - *, - actor_id: str | None = None, - actor_task_id: str | None = None, - actor_run_id: str | None = None, -) -> dict: - """Build webhook condition dictionary.""" - return { - 'actorRunId': actor_run_id, - 'actorTaskId': actor_task_id, - 'actorId': actor_id, - } - - -def get_actor_repr( - *, - name: str | None, - title: str | None = None, - description: str | None = None, - seo_title: str | None = None, - seo_description: str | None = None, - versions: list[dict] | None = None, - restart_on_error: bool | None = None, - is_public: bool | None = None, - is_deprecated: bool | None = None, - is_anonymously_runnable: bool | None = None, - categories: list[str] | None = None, - default_run_build: str | None = None, - default_run_max_items: int | None = None, - default_run_memory_mbytes: int | None = None, - default_run_timeout: timedelta | None = None, - default_run_force_permission_level: ActorPermissionLevel | None = None, - example_run_input_body: Any = None, - example_run_input_content_type: str | None = None, - actor_standby_is_enabled: bool | None = None, - actor_standby_desired_requests_per_actor_run: int | None = None, - actor_standby_max_requests_per_actor_run: int | None = None, - actor_standby_idle_timeout: timedelta | None = None, - actor_standby_build: str | None = None, - actor_standby_memory_mbytes: int | None = None, - pricing_infos: list[dict] | None = None, - actor_permission_level: ActorPermissionLevel | None = None, - tagged_builds: dict[str, None | dict[str, str]] | None = None, -) -> dict: - """Get dictionary representation of the Actor.""" - actor_dict: dict[str, Any] = { - 'name': name, - 'title': title, - 'description': description, - 'seoTitle': seo_title, - 'seoDescription': seo_description, - 'versions': versions, - 'isPublic': is_public, - 'isDeprecated': is_deprecated, - 'isAnonymouslyRunnable': is_anonymously_runnable, - 'categories': categories, - 'pricingInfos': pricing_infos, - 'actorPermissionLevel': actor_permission_level, - 'defaultRunOptions': build_default_run_options_dict( - build=default_run_build, - max_items=default_run_max_items, - memory_mbytes=default_run_memory_mbytes, - timeout=default_run_timeout, - restart_on_error=restart_on_error, - force_permission_level=default_run_force_permission_level, - ), - 'actorStandby': build_actor_standby_dict( - is_enabled=actor_standby_is_enabled, - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout=actor_standby_idle_timeout, - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, - ), - 'exampleRunInput': build_example_run_input_dict( - body=example_run_input_body, - content_type=example_run_input_content_type, - ), - } - - # Include taggedBuilds if provided - if tagged_builds is not None: - actor_dict['taggedBuilds'] = tagged_builds - - return actor_dict - - -def get_task_repr( - *, - actor_id: str | None = None, - name: str | None = None, - task_input: dict | None = None, - build: str | None = None, - max_items: int | None = None, - memory_mbytes: int | None = None, - timeout: timedelta | None = None, - title: str | None = None, - actor_standby_desired_requests_per_actor_run: int | None = None, - actor_standby_max_requests_per_actor_run: int | None = None, - actor_standby_idle_timeout: timedelta | None = None, - actor_standby_build: str | None = None, - actor_standby_memory_mbytes: int | None = None, - restart_on_error: bool | None = None, -) -> dict: - """Get the dictionary representation of a task.""" - return { - 'actId': actor_id, - 'name': name, - 'title': title, - 'input': task_input, - 'options': build_task_options_dict( - build=build, - max_items=max_items, - memory_mbytes=memory_mbytes, - timeout=timeout, - restart_on_error=restart_on_error, - ), - 'actorStandby': build_actor_standby_dict( - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout=actor_standby_idle_timeout, - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, - ), - } - - -def get_actor_version_repr( - *, - version_number: str | None = None, - build_tag: str | None = None, - env_vars: list[dict] | None = None, - apply_env_vars_to_build: bool | None = None, - source_type: VersionSourceType | None = None, - source_files: list[dict] | None = None, - git_repo_url: str | None = None, - tarball_url: str | None = None, - github_gist_url: str | None = None, -) -> dict: - """Get dictionary representation of an Actor version.""" - return { - 'versionNumber': version_number, - 'buildTag': build_tag, - 'envVars': env_vars, - 'applyEnvVarsToBuild': apply_env_vars_to_build, - 'sourceType': enum_to_value(source_type), - 'sourceFiles': source_files, - 'gitRepoUrl': git_repo_url, - 'tarballUrl': tarball_url, - 'gitHubGistUrl': github_gist_url, - } - - -def get_schedule_repr( - *, - cron_expression: str | None = None, - name: str | None = None, - actions: list[dict] | None = None, - description: str | None = None, - timezone: str | None = None, - title: str | None = None, - is_enabled: bool | None = None, - is_exclusive: bool | None = None, -) -> dict: - """Get dictionary representation of a schedule.""" - return { - 'cronExpression': cron_expression, - 'isEnabled': is_enabled, - 'isExclusive': is_exclusive, - 'name': name, - 'actions': actions, - 'description': description, - 'timezone': timezone, - 'title': title, - } - - -def get_webhook_repr( - *, - event_types: list[WebhookEventType] | None = None, - request_url: str | None = None, - payload_template: str | None = None, - headers_template: str | None = None, - actor_id: str | None = None, - actor_task_id: str | None = None, - actor_run_id: str | None = None, - ignore_ssl_errors: bool | None = None, - do_not_retry: bool | None = None, - idempotency_key: str | None = None, - is_ad_hoc: bool | None = None, -) -> dict: - """Prepare webhook dictionary representation for clients.""" - webhook: dict[str, Any] = { - 'requestUrl': request_url, - 'payloadTemplate': payload_template, - 'headersTemplate': headers_template, - 'ignoreSslErrors': ignore_ssl_errors, - 'doNotRetry': do_not_retry, - 'idempotencyKey': idempotency_key, - 'isAdHoc': is_ad_hoc, - 'condition': build_webhook_condition_dict( - actor_id=actor_id, - actor_task_id=actor_task_id, - actor_run_id=actor_run_id, - ), - } - - if actor_run_id is not None and is_ad_hoc is None: - webhook['isAdHoc'] = True - - if event_types is not None: - webhook['eventTypes'] = [enum_to_value(event_type) for event_type in event_types] - - return webhook diff --git a/src/apify_client/_resource_clients/_resource_client.py b/src/apify_client/_resource_clients/_resource_client.py index 5f271ee8..a2847499 100644 --- a/src/apify_client/_resource_clients/_resource_client.py +++ b/src/apify_client/_resource_clients/_resource_client.py @@ -120,6 +120,41 @@ def _build_params(self, **kwargs: Any) -> dict: merged = {**self._default_params, **kwargs} return {k: v for k, v in merged.items() if v is not None} + @staticmethod + def _clean_json_payload(data: dict) -> dict: + """Remove None values and empty nested dicts from an API request payload. + + The Apify API ignores missing fields but may reject fields explicitly set to None. + Nested sub-models serialized by Pydantic may produce empty dicts when all their + fields are None — these are also removed. + + Uses an iterative stack-based approach, analogous to _build_params for query params. + """ + result: dict = {} + stack: list[tuple[dict, dict]] = [(data, result)] + + while stack: + source, target = stack.pop() + for key, val in source.items(): + if val is None: + continue + if isinstance(val, dict): + nested: dict = {} + target[key] = nested + stack.append((val, nested)) + else: + target[key] = val + + # Remove dicts that became empty after None filtering + def _remove_empty(d: dict) -> None: + for key in [k for k, v in d.items() if isinstance(v, dict)]: + _remove_empty(d[key]) + if not d[key]: + del d[key] + + _remove_empty(result) + return result + @docs_group('Resource clients') class ResourceClient(ResourceClientBase): @@ -171,13 +206,13 @@ def _get(self, *, timeout: timedelta | None = None) -> dict | None: catch_not_found_or_throw(exc) return None - def _update(self, updated_fields: dict, *, timeout: timedelta | None = None) -> dict: + def _update(self, *, timeout: timedelta | None = None, **kwargs: Any) -> dict: """Perform a PUT request to update this resource with the given fields.""" response = self._http_client.call( url=self._build_url(), method='PUT', params=self._build_params(), - json=updated_fields, + json=self._clean_json_payload(kwargs), timeout=timeout, ) return response_to_dict(response) @@ -203,13 +238,13 @@ def _list(self, **kwargs: Any) -> dict: ) return response_to_dict(response) - def _create(self, created_fields: dict) -> dict: + def _create(self, **kwargs: Any) -> dict: """Perform a POST request to create a resource.""" response = self._http_client.call( url=self._build_url(), method='POST', params=self._build_params(), - json=created_fields, + json=self._clean_json_payload(kwargs), ) return response_to_dict(response) @@ -219,7 +254,7 @@ def _get_or_create(self, *, name: str | None = None, resource_fields: dict | Non url=self._build_url(), method='POST', params=self._build_params(name=name), - json=resource_fields, + json=self._clean_json_payload(resource_fields) if resource_fields is not None else None, ) return response_to_dict(response) @@ -338,13 +373,13 @@ async def _get(self, *, timeout: timedelta | None = None) -> dict | None: catch_not_found_or_throw(exc) return None - async def _update(self, updated_fields: dict, *, timeout: timedelta | None = None) -> dict: + async def _update(self, *, timeout: timedelta | None = None, **kwargs: Any) -> dict: """Perform a PUT request to update this resource with the given fields.""" response = await self._http_client.call( url=self._build_url(), method='PUT', params=self._build_params(), - json=updated_fields, + json=self._clean_json_payload(kwargs), timeout=timeout, ) return response_to_dict(response) @@ -370,13 +405,13 @@ async def _list(self, **kwargs: Any) -> dict: ) return response_to_dict(response) - async def _create(self, created_fields: dict) -> dict: + async def _create(self, **kwargs: Any) -> dict: """Perform a POST request to create a resource.""" response = await self._http_client.call( url=self._build_url(), method='POST', params=self._build_params(), - json=created_fields, + json=self._clean_json_payload(kwargs), ) return response_to_dict(response) @@ -386,7 +421,7 @@ async def _get_or_create(self, *, name: str | None = None, resource_fields: dict url=self._build_url(), method='POST', params=self._build_params(name=name), - json=resource_fields, + json=self._clean_json_payload(resource_fields) if resource_fields is not None else None, ) return response_to_dict(response) diff --git a/src/apify_client/_resource_clients/actor.py b/src/apify_client/_resource_clients/actor.py index c7000e66..45b3c370 100644 --- a/src/apify_client/_resource_clients/actor.py +++ b/src/apify_client/_resource_clients/actor.py @@ -2,24 +2,32 @@ from typing import TYPE_CHECKING, Any, Literal +from pydantic import TypeAdapter + from apify_client._docs import docs_group from apify_client._models import ( Actor, ActorPermissionLevel, ActorResponse, + ActorStandby, Build, BuildResponse, + CreateOrUpdateVersionRequest, + DefaultRunOptions, + ExampleRunInput, + FlatPricePerMonthActorPricingInfo, + FreeActorPricingInfo, + PayPerEventActorPricingInfo, + PricePerDatasetItemActorPricingInfo, Run, RunOrigin, RunResponse, + UpdateActorRequest, ) -from apify_client._representations import get_actor_repr from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync from apify_client._utils import ( encode_key_value_store_record_value, encode_webhook_list_to_base64, - enum_to_value, - filter_none_values, response_to_dict, to_seconds, ) @@ -47,6 +55,14 @@ WebhookCollectionClientAsync, ) +_PricingInfo = ( + PayPerEventActorPricingInfo + | PricePerDatasetItemActorPricingInfo + | FlatPricePerMonthActorPricingInfo + | FreeActorPricingInfo +) +_pricing_info_list_adapter = TypeAdapter(list[_PricingInfo]) + @docs_group('Resource clients') class ActorClient(ResourceClient): @@ -90,11 +106,10 @@ def update( description: str | None = None, seo_title: str | None = None, seo_description: str | None = None, - versions: list[dict] | None = None, + versions: list[dict[str, Any]] | None = None, restart_on_error: bool | None = None, is_public: bool | None = None, is_deprecated: bool | None = None, - is_anonymously_runnable: bool | None = None, categories: list[str] | None = None, default_run_build: str | None = None, default_run_max_items: int | None = None, @@ -108,7 +123,7 @@ def update( actor_standby_idle_timeout: timedelta | None = None, actor_standby_build: str | None = None, actor_standby_memory_mbytes: int | None = None, - pricing_infos: list[dict] | None = None, + pricing_infos: list[dict[str, Any]] | None = None, actor_permission_level: ActorPermissionLevel | None = None, tagged_builds: dict[str, None | dict[str, str]] | None = None, ) -> Actor: @@ -127,7 +142,6 @@ def update( a non-zero status code. is_public: Whether the Actor is public. is_deprecated: Whether the Actor is deprecated. - is_anonymously_runnable: Whether the Actor is anonymously runnable. categories: The categories to which the Actor belongs to. default_run_build: Tag or number of the build that you want to run by default. default_run_max_items: Default limit of the number of results that will be returned @@ -154,37 +168,40 @@ def update( Returns: The updated Actor. """ - actor_representation = get_actor_repr( + request = UpdateActorRequest( name=name, title=title, description=description, seo_title=seo_title, seo_description=seo_description, - versions=versions, - restart_on_error=restart_on_error, + versions=[CreateOrUpdateVersionRequest.model_validate(v) for v in versions] if versions else None, is_public=is_public, is_deprecated=is_deprecated, - is_anonymously_runnable=is_anonymously_runnable, categories=categories, - default_run_build=default_run_build, - default_run_max_items=default_run_max_items, - default_run_memory_mbytes=default_run_memory_mbytes, - default_run_timeout=default_run_timeout, - example_run_input_body=example_run_input_body, - example_run_input_content_type=example_run_input_content_type, - actor_standby_is_enabled=actor_standby_is_enabled, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, - pricing_infos=pricing_infos, + pricing_infos=_pricing_info_list_adapter.validate_python(pricing_infos) if pricing_infos else None, actor_permission_level=actor_permission_level, + default_run_options=DefaultRunOptions( + build=default_run_build, + max_items=default_run_max_items, + memory_mbytes=default_run_memory_mbytes, + timeout_secs=to_seconds(default_run_timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + is_enabled=actor_standby_is_enabled, + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), + example_run_input=ExampleRunInput( + body=example_run_input_body, + content_type=example_run_input_content_type, + ), tagged_builds=tagged_builds, ) - cleaned = filter_none_values(actor_representation, remove_empty_dicts=True) - - result = self._update(cleaned) + result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data def delete(self) -> None: @@ -458,8 +475,8 @@ def last_run( resource_id='last', resource_path='runs', params=self._build_params( - status=enum_to_value(status), - origin=enum_to_value(origin), + status=status, + origin=origin, ), **self._base_client_kwargs, ) @@ -554,11 +571,10 @@ async def update( description: str | None = None, seo_title: str | None = None, seo_description: str | None = None, - versions: list[dict] | None = None, + versions: list[dict[str, Any]] | None = None, restart_on_error: bool | None = None, is_public: bool | None = None, is_deprecated: bool | None = None, - is_anonymously_runnable: bool | None = None, categories: list[str] | None = None, default_run_build: str | None = None, default_run_max_items: int | None = None, @@ -572,7 +588,7 @@ async def update( actor_standby_idle_timeout: timedelta | None = None, actor_standby_build: str | None = None, actor_standby_memory_mbytes: int | None = None, - pricing_infos: list[dict] | None = None, + pricing_infos: list[dict[str, Any]] | None = None, actor_permission_level: ActorPermissionLevel | None = None, tagged_builds: dict[str, None | dict[str, str]] | None = None, ) -> Actor: @@ -591,7 +607,6 @@ async def update( a non-zero status code. is_public: Whether the Actor is public. is_deprecated: Whether the Actor is deprecated. - is_anonymously_runnable: Whether the Actor is anonymously runnable. categories: The categories to which the Actor belongs to. default_run_build: Tag or number of the build that you want to run by default. default_run_max_items: Default limit of the number of results that will be returned @@ -618,37 +633,40 @@ async def update( Returns: The updated Actor. """ - actor_representation = get_actor_repr( + request = UpdateActorRequest( name=name, title=title, description=description, seo_title=seo_title, seo_description=seo_description, - versions=versions, - restart_on_error=restart_on_error, + versions=[CreateOrUpdateVersionRequest.model_validate(v) for v in versions] if versions else None, is_public=is_public, is_deprecated=is_deprecated, - is_anonymously_runnable=is_anonymously_runnable, categories=categories, - default_run_build=default_run_build, - default_run_max_items=default_run_max_items, - default_run_memory_mbytes=default_run_memory_mbytes, - default_run_timeout=default_run_timeout, - example_run_input_body=example_run_input_body, - example_run_input_content_type=example_run_input_content_type, - actor_standby_is_enabled=actor_standby_is_enabled, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, - pricing_infos=pricing_infos, + pricing_infos=_pricing_info_list_adapter.validate_python(pricing_infos) if pricing_infos else None, actor_permission_level=actor_permission_level, + default_run_options=DefaultRunOptions( + build=default_run_build, + max_items=default_run_max_items, + memory_mbytes=default_run_memory_mbytes, + timeout_secs=to_seconds(default_run_timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + is_enabled=actor_standby_is_enabled, + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), + example_run_input=ExampleRunInput( + body=example_run_input_body, + content_type=example_run_input_content_type, + ), tagged_builds=tagged_builds, ) - cleaned = filter_none_values(actor_representation, remove_empty_dicts=True) - - result = await self._update(cleaned) + result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data async def delete(self) -> None: @@ -930,8 +948,8 @@ def last_run( resource_id='last', resource_path='runs', params=self._build_params( - status=enum_to_value(status), - origin=enum_to_value(origin), + status=status, + origin=origin, ), **self._base_client_kwargs, ) diff --git a/src/apify_client/_resource_clients/actor_collection.py b/src/apify_client/_resource_clients/actor_collection.py index 255d9f9c..1ea01ea8 100644 --- a/src/apify_client/_resource_clients/actor_collection.py +++ b/src/apify_client/_resource_clients/actor_collection.py @@ -3,10 +3,18 @@ from typing import TYPE_CHECKING, Any, Literal from apify_client._docs import docs_group -from apify_client._models import Actor, ActorResponse, ListOfActors, ListOfActorsResponse -from apify_client._representations import get_actor_repr +from apify_client._models import ( + Actor, + ActorResponse, + ActorStandby, + CreateActorRequest, + DefaultRunOptions, + ExampleRunInput, + ListOfActors, + ListOfActorsResponse, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values +from apify_client._utils import to_seconds if TYPE_CHECKING: from datetime import timedelta @@ -58,11 +66,10 @@ def create( description: str | None = None, seo_title: str | None = None, seo_description: str | None = None, - versions: list[dict] | None = None, # ty: ignore[invalid-type-form] + versions: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] restart_on_error: bool | None = None, is_public: bool | None = None, is_deprecated: bool | None = None, - is_anonymously_runnable: bool | None = None, categories: list[str] | None = None, # ty: ignore[invalid-type-form] default_run_build: str | None = None, default_run_max_items: int | None = None, @@ -92,7 +99,6 @@ def create( a non-zero status code. is_public: Whether the Actor is public. is_deprecated: Whether the Actor is deprecated. - is_anonymously_runnable: Whether the Actor is anonymously runnable. categories: The categories to which the Actor belongs to. default_run_build: Tag or number of the build that you want to run by default. default_run_max_items: Default limit of the number of results that will be returned by runs @@ -114,33 +120,37 @@ def create( Returns: The created Actor. """ - actor_representation = get_actor_repr( + request = CreateActorRequest( name=name, title=title, description=description, seo_title=seo_title, seo_description=seo_description, versions=versions, - restart_on_error=restart_on_error, is_public=is_public, is_deprecated=is_deprecated, - is_anonymously_runnable=is_anonymously_runnable, categories=categories, - default_run_build=default_run_build, - default_run_max_items=default_run_max_items, - default_run_memory_mbytes=default_run_memory_mbytes, - default_run_timeout=default_run_timeout, - example_run_input_body=example_run_input_body, - example_run_input_content_type=example_run_input_content_type, - actor_standby_is_enabled=actor_standby_is_enabled, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, + default_run_options=DefaultRunOptions( + build=default_run_build, + max_items=default_run_max_items, + memory_mbytes=default_run_memory_mbytes, + timeout_secs=to_seconds(default_run_timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + is_enabled=actor_standby_is_enabled, + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), + example_run_input=ExampleRunInput( + body=example_run_input_body, + content_type=example_run_input_content_type, + ), ) - - result = self._create(filter_none_values(actor_representation, remove_empty_dicts=True)) + result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data @@ -190,11 +200,10 @@ async def create( description: str | None = None, seo_title: str | None = None, seo_description: str | None = None, - versions: list[dict] | None = None, # ty: ignore[invalid-type-form] + versions: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] restart_on_error: bool | None = None, is_public: bool | None = None, is_deprecated: bool | None = None, - is_anonymously_runnable: bool | None = None, categories: list[str] | None = None, # ty: ignore[invalid-type-form] default_run_build: str | None = None, default_run_max_items: int | None = None, @@ -224,7 +233,6 @@ async def create( a non-zero status code. is_public: Whether the Actor is public. is_deprecated: Whether the Actor is deprecated. - is_anonymously_runnable: Whether the Actor is anonymously runnable. categories: The categories to which the Actor belongs to. default_run_build: Tag or number of the build that you want to run by default. default_run_max_items: Default limit of the number of results that will be returned by runs @@ -246,31 +254,35 @@ async def create( Returns: The created Actor. """ - actor_representation = get_actor_repr( + request = CreateActorRequest( name=name, title=title, description=description, seo_title=seo_title, seo_description=seo_description, versions=versions, - restart_on_error=restart_on_error, is_public=is_public, is_deprecated=is_deprecated, - is_anonymously_runnable=is_anonymously_runnable, categories=categories, - default_run_build=default_run_build, - default_run_max_items=default_run_max_items, - default_run_memory_mbytes=default_run_memory_mbytes, - default_run_timeout=default_run_timeout, - example_run_input_body=example_run_input_body, - example_run_input_content_type=example_run_input_content_type, - actor_standby_is_enabled=actor_standby_is_enabled, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, + default_run_options=DefaultRunOptions( + build=default_run_build, + max_items=default_run_max_items, + memory_mbytes=default_run_memory_mbytes, + timeout_secs=to_seconds(default_run_timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + is_enabled=actor_standby_is_enabled, + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), + example_run_input=ExampleRunInput( + body=example_run_input_body, + content_type=example_run_input_content_type, + ), ) - - result = await self._create(filter_none_values(actor_representation, remove_empty_dicts=True)) + result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/actor_env_var.py b/src/apify_client/_resource_clients/actor_env_var.py index ea5acce9..f14b3f8d 100644 --- a/src/apify_client/_resource_clients/actor_env_var.py +++ b/src/apify_client/_resource_clients/actor_env_var.py @@ -5,21 +5,6 @@ from apify_client._docs import docs_group from apify_client._models import EnvVar, EnvVarResponse from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values - - -def get_actor_env_var_representation( - *, - is_secret: bool | None = None, - name: str | None = None, - value: str | None = None, -) -> dict: - """Return an environment variable representation of the Actor in a dictionary.""" - return { - 'isSecret': is_secret, - 'name': name, - 'value': value, - } @docs_group('Resource clients') @@ -66,13 +51,9 @@ def update( Returns: The updated Actor environment variable. """ - actor_env_var_representation = get_actor_env_var_representation( - is_secret=is_secret, - name=name, - value=value, + result = self._update( + **EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True) ) - cleaned = filter_none_values(actor_env_var_representation) - result = self._update(cleaned) return EnvVarResponse.model_validate(result).data def delete(self) -> None: @@ -127,13 +108,9 @@ async def update( Returns: The updated Actor environment variable. """ - actor_env_var_representation = get_actor_env_var_representation( - is_secret=is_secret, - name=name, - value=value, + result = await self._update( + **EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True) ) - cleaned = filter_none_values(actor_env_var_representation) - result = await self._update(cleaned) return EnvVarResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/actor_env_var_collection.py b/src/apify_client/_resource_clients/actor_env_var_collection.py index 4a82fb6a..5462921a 100644 --- a/src/apify_client/_resource_clients/actor_env_var_collection.py +++ b/src/apify_client/_resource_clients/actor_env_var_collection.py @@ -5,8 +5,6 @@ from apify_client._docs import docs_group from apify_client._models import EnvVar, EnvVarResponse, ListOfEnvVars, ListOfEnvVarsResponse from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._resource_clients.actor_env_var import get_actor_env_var_representation -from apify_client._utils import filter_none_values @docs_group('Resource clients') @@ -51,13 +49,9 @@ def create( Returns: The created Actor environment variable. """ - actor_env_var_representation = get_actor_env_var_representation( - is_secret=is_secret, - name=name, - value=value, + result = self._create( + **EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True) ) - - result = self._create(filter_none_values(actor_env_var_representation)) return EnvVarResponse.model_validate(result).data @@ -103,11 +97,7 @@ async def create( Returns: The created Actor environment variable. """ - actor_env_var_representation = get_actor_env_var_representation( - is_secret=is_secret, - name=name, - value=value, + result = await self._create( + **EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True) ) - - result = await self._create(filter_none_values(actor_env_var_representation)) return EnvVarResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/actor_version.py b/src/apify_client/_resource_clients/actor_version.py index ce53e521..9fac9ba7 100644 --- a/src/apify_client/_resource_clients/actor_version.py +++ b/src/apify_client/_resource_clients/actor_version.py @@ -2,11 +2,19 @@ from typing import TYPE_CHECKING, Any +from pydantic import TypeAdapter + from apify_client._docs import docs_group -from apify_client._models import Version, VersionResponse, VersionSourceType -from apify_client._representations import get_actor_version_repr +from apify_client._models import ( + CreateOrUpdateVersionRequest, + EnvVar, + SourceCodeFile, + SourceCodeFolder, + Version, + VersionResponse, + VersionSourceType, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values if TYPE_CHECKING: from apify_client._resource_clients import ( @@ -16,6 +24,8 @@ ActorEnvVarCollectionClientAsync, ) +_source_file_list_adapter = TypeAdapter(list[SourceCodeFile | SourceCodeFolder]) + @docs_group('Resource clients') class ActorVersionClient(ResourceClient): @@ -55,10 +65,10 @@ def update( self, *, build_tag: str | None = None, - env_vars: list[dict] | None = None, + env_vars: list[dict[str, Any]] | None = None, apply_env_vars_to_build: bool | None = None, source_type: VersionSourceType | None = None, - source_files: list[dict] | None = None, + source_files: list[dict[str, Any]] | None = None, git_repo_url: str | None = None, tarball_url: str | None = None, github_gist_url: str | None = None, @@ -86,19 +96,17 @@ def update( Returns: The updated Actor version. """ - actor_version_representation = get_actor_version_repr( + request = CreateOrUpdateVersionRequest( build_tag=build_tag, - env_vars=env_vars, + env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, apply_env_vars_to_build=apply_env_vars_to_build, source_type=source_type, - source_files=source_files, + source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None, git_repo_url=git_repo_url, tarball_url=tarball_url, github_gist_url=github_gist_url, ) - cleaned = filter_none_values(actor_version_representation) - - result = self._update(cleaned) + result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data def delete(self) -> None: @@ -165,10 +173,10 @@ async def update( self, *, build_tag: str | None = None, - env_vars: list[dict] | None = None, + env_vars: list[dict[str, Any]] | None = None, apply_env_vars_to_build: bool | None = None, source_type: VersionSourceType | None = None, - source_files: list[dict] | None = None, + source_files: list[dict[str, Any]] | None = None, git_repo_url: str | None = None, tarball_url: str | None = None, github_gist_url: str | None = None, @@ -196,19 +204,17 @@ async def update( Returns: The updated Actor version. """ - actor_version_representation = get_actor_version_repr( + request = CreateOrUpdateVersionRequest( build_tag=build_tag, - env_vars=env_vars, + env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, apply_env_vars_to_build=apply_env_vars_to_build, source_type=source_type, - source_files=source_files, + source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None, git_repo_url=git_repo_url, tarball_url=tarball_url, github_gist_url=github_gist_url, ) - cleaned = filter_none_values(actor_version_representation) - - result = await self._update(cleaned) + result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/actor_version_collection.py b/src/apify_client/_resource_clients/actor_version_collection.py index bde7517b..edecd406 100644 --- a/src/apify_client/_resource_clients/actor_version_collection.py +++ b/src/apify_client/_resource_clients/actor_version_collection.py @@ -2,17 +2,23 @@ from typing import Any +from pydantic import TypeAdapter + from apify_client._docs import docs_group from apify_client._models import ( + CreateOrUpdateVersionRequest, + EnvVar, ListOfVersions, ListOfVersionsResponse, + SourceCodeFile, + SourceCodeFolder, Version, VersionResponse, VersionSourceType, ) -from apify_client._representations import get_actor_version_repr from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values + +_source_file_list_adapter = TypeAdapter(list[SourceCodeFile | SourceCodeFolder]) @docs_group('Resource clients') @@ -43,10 +49,10 @@ def create( *, version_number: str, build_tag: str | None = None, - env_vars: list[dict] | None = None, # ty: ignore[invalid-type-form] + env_vars: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] apply_env_vars_to_build: bool | None = None, source_type: VersionSourceType, - source_files: list[dict] | None = None, # ty: ignore[invalid-type-form] + source_files: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] git_repo_url: str | None = None, tarball_url: str | None = None, github_gist_url: str | None = None, @@ -75,19 +81,18 @@ def create( Returns: The created Actor version. """ - actor_version_representation = get_actor_version_repr( + request = CreateOrUpdateVersionRequest( version_number=version_number, build_tag=build_tag, - env_vars=env_vars, + env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, apply_env_vars_to_build=apply_env_vars_to_build, source_type=source_type, - source_files=source_files, + source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None, git_repo_url=git_repo_url, tarball_url=tarball_url, github_gist_url=github_gist_url, ) - - result = self._create(filter_none_values(actor_version_representation)) + result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data @@ -119,10 +124,10 @@ async def create( *, version_number: str, build_tag: str | None = None, - env_vars: list[dict] | None = None, # ty: ignore[invalid-type-form] + env_vars: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] apply_env_vars_to_build: bool | None = None, source_type: VersionSourceType, - source_files: list[dict] | None = None, # ty: ignore[invalid-type-form] + source_files: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] git_repo_url: str | None = None, tarball_url: str | None = None, github_gist_url: str | None = None, @@ -151,17 +156,16 @@ async def create( Returns: The created Actor version. """ - actor_version_representation = get_actor_version_repr( + request = CreateOrUpdateVersionRequest( version_number=version_number, build_tag=build_tag, - env_vars=env_vars, + env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, apply_env_vars_to_build=apply_env_vars_to_build, source_type=source_type, - source_files=source_files, + source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None, git_repo_url=git_repo_url, tarball_url=tarball_url, github_gist_url=github_gist_url, ) - - result = await self._create(filter_none_values(actor_version_representation)) + result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/dataset.py b/src/apify_client/_resource_clients/dataset.py index f87f13f0..aded836e 100644 --- a/src/apify_client/_resource_clients/dataset.py +++ b/src/apify_client/_resource_clients/dataset.py @@ -13,7 +13,6 @@ from apify_client._utils import ( catch_not_found_or_throw, create_storage_content_signature, - filter_none_values, response_to_dict, response_to_list, ) @@ -94,13 +93,7 @@ def update(self, *, name: str | None = None, general_access: GeneralAccess | Non Returns: The updated dataset. """ - updated_fields = { - 'name': name, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = self._update(cleaned, timeout=FAST_OPERATION_TIMEOUT) + result = self._update(timeout=FAST_OPERATION_TIMEOUT, name=name, generalAccess=general_access) return DatasetResponse.model_validate(result).data def delete(self) -> None: @@ -715,13 +708,7 @@ async def update(self, *, name: str | None = None, general_access: GeneralAccess Returns: The updated dataset. """ - updated_fields = { - 'name': name, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = await self._update(cleaned, timeout=FAST_OPERATION_TIMEOUT) + result = await self._update(timeout=FAST_OPERATION_TIMEOUT, name=name, generalAccess=general_access) return DatasetResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/dataset_collection.py b/src/apify_client/_resource_clients/dataset_collection.py index 2322fd67..be303b82 100644 --- a/src/apify_client/_resource_clients/dataset_collection.py +++ b/src/apify_client/_resource_clients/dataset_collection.py @@ -5,7 +5,6 @@ from apify_client._docs import docs_group from apify_client._models import Dataset, DatasetResponse, ListOfDatasets, ListOfDatasetsResponse from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values @docs_group('Resource clients') @@ -56,7 +55,7 @@ def get_or_create(self, *, name: str | None = None, schema: dict | None = None) Returns: The retrieved or newly-created dataset. """ - result = self._get_or_create(name=name, resource_fields=filter_none_values({'schema': schema})) + result = self._get_or_create(name=name, resource_fields={'schema': schema}) return DatasetResponse.model_validate(result).data @@ -113,5 +112,5 @@ async def get_or_create( Returns: The retrieved or newly-created dataset. """ - result = await self._get_or_create(name=name, resource_fields=filter_none_values({'schema': schema})) + result = await self._get_or_create(name=name, resource_fields={'schema': schema}) return DatasetResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/key_value_store.py b/src/apify_client/_resource_clients/key_value_store.py index f3278f4d..6d2cf243 100644 --- a/src/apify_client/_resource_clients/key_value_store.py +++ b/src/apify_client/_resource_clients/key_value_store.py @@ -21,7 +21,6 @@ create_hmac_signature, create_storage_content_signature, encode_key_value_store_record_value, - filter_none_values, response_to_dict, ) from apify_client.errors import ApifyApiError, InvalidResponseBodyError @@ -105,13 +104,7 @@ def update(self, *, name: str | None = None, general_access: GeneralAccess | Non Returns: The updated key-value store. """ - updated_fields = { - 'name': name, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = self._update(cleaned, timeout=FAST_OPERATION_TIMEOUT) + result = self._update(timeout=FAST_OPERATION_TIMEOUT, name=name, generalAccess=general_access) return KeyValueStoreResponse.model_validate(result).data def delete(self) -> None: @@ -494,13 +487,7 @@ async def update( Returns: The updated key-value store. """ - updated_fields = { - 'name': name, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = await self._update(cleaned, timeout=FAST_OPERATION_TIMEOUT) + result = await self._update(timeout=FAST_OPERATION_TIMEOUT, name=name, generalAccess=general_access) return KeyValueStoreResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/key_value_store_collection.py b/src/apify_client/_resource_clients/key_value_store_collection.py index f693952d..37691eb1 100644 --- a/src/apify_client/_resource_clients/key_value_store_collection.py +++ b/src/apify_client/_resource_clients/key_value_store_collection.py @@ -10,7 +10,6 @@ ListOfKeyValueStoresResponse, ) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values @docs_group('Resource clients') @@ -66,7 +65,7 @@ def get_or_create( Returns: The retrieved or newly-created key-value store. """ - result = self._get_or_create(name=name, resource_fields=filter_none_values({'schema': schema})) + result = self._get_or_create(name=name, resource_fields={'schema': schema}) return KeyValueStoreResponse.model_validate(result).data @@ -123,5 +122,5 @@ async def get_or_create( Returns: The retrieved or newly-created key-value store. """ - result = await self._get_or_create(name=name, resource_fields=filter_none_values({'schema': schema})) + result = await self._get_or_create(name=name, resource_fields={'schema': schema}) return KeyValueStoreResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/request_queue.py b/src/apify_client/_resource_clients/request_queue.py index 408a3d73..3ae18519 100644 --- a/src/apify_client/_resource_clients/request_queue.py +++ b/src/apify_client/_resource_clients/request_queue.py @@ -36,7 +36,7 @@ UnlockRequestsResult, ) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import catch_not_found_or_throw, filter_none_values, response_to_dict, to_seconds +from apify_client._utils import catch_not_found_or_throw, response_to_dict, to_seconds from apify_client.errors import ApifyApiError if TYPE_CHECKING: @@ -100,13 +100,7 @@ def update(self, *, name: str | None = None, general_access: GeneralAccess | Non Returns: The updated request queue. """ - updated_fields = { - 'name': name, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = self._update(cleaned, timeout=FAST_OPERATION_TIMEOUT) + result = self._update(timeout=FAST_OPERATION_TIMEOUT, name=name, generalAccess=general_access) return RequestQueueResponse.model_validate(result).data def delete(self) -> None: @@ -515,13 +509,7 @@ async def update( Returns: The updated request queue. """ - updated_fields = { - 'name': name, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = await self._update(cleaned, timeout=FAST_OPERATION_TIMEOUT) + result = await self._update(timeout=FAST_OPERATION_TIMEOUT, name=name, generalAccess=general_access) return RequestQueueResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/run.py b/src/apify_client/_resource_clients/run.py index 1f7da905..255ae095 100644 --- a/src/apify_client/_resource_clients/run.py +++ b/src/apify_client/_resource_clients/run.py @@ -15,7 +15,6 @@ from apify_client._streamed_log import StreamedLog, StreamedLogAsync from apify_client._utils import ( encode_key_value_store_record_value, - filter_none_values, response_to_dict, to_safe_id, to_seconds, @@ -91,14 +90,11 @@ def update( Returns: The updated run. """ - updated_fields = { - 'statusMessage': status_message, - 'isStatusMessageTerminal': is_status_message_terminal, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = self._update(cleaned) + result = self._update( + statusMessage=status_message, + isStatusMessageTerminal=is_status_message_terminal, + generalAccess=general_access, + ) return RunResponse.model_validate(result).data def delete(self) -> None: @@ -485,14 +481,11 @@ async def update( Returns: The updated run. """ - updated_fields = { - 'statusMessage': status_message, - 'isStatusMessageTerminal': is_status_message_terminal, - 'generalAccess': general_access, - } - cleaned = filter_none_values(updated_fields) - - result = await self._update(cleaned) + result = await self._update( + statusMessage=status_message, + isStatusMessageTerminal=is_status_message_terminal, + generalAccess=general_access, + ) return RunResponse.model_validate(result).data async def abort(self, *, gracefully: bool | None = None) -> Run: diff --git a/src/apify_client/_resource_clients/run_collection.py b/src/apify_client/_resource_clients/run_collection.py index 2cf32801..ab7a1a20 100644 --- a/src/apify_client/_resource_clients/run_collection.py +++ b/src/apify_client/_resource_clients/run_collection.py @@ -5,7 +5,6 @@ from apify_client._docs import docs_group from apify_client._models import ListOfRuns, ListOfRunsResponse from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import enum_to_value if TYPE_CHECKING: from datetime import datetime @@ -54,7 +53,7 @@ def list( Returns: The retrieved Actor runs. """ - status_param = [enum_to_value(s) for s in status] if isinstance(status, list) else enum_to_value(status) + status_param = list(status) if isinstance(status, list) else status result = self._list( limit=limit, @@ -108,7 +107,7 @@ async def list( Returns: The retrieved Actor runs. """ - status_param = [enum_to_value(s) for s in status] if isinstance(status, list) else enum_to_value(status) + status_param = list(status) if isinstance(status, list) else status result = await self._list( limit=limit, diff --git a/src/apify_client/_resource_clients/schedule.py b/src/apify_client/_resource_clients/schedule.py index 63bd4ebd..800ce0d4 100644 --- a/src/apify_client/_resource_clients/schedule.py +++ b/src/apify_client/_resource_clients/schedule.py @@ -3,10 +3,16 @@ from typing import Any from apify_client._docs import docs_group -from apify_client._models import Schedule, ScheduleInvoked, ScheduleLogResponse, ScheduleResponse -from apify_client._representations import get_schedule_repr +from apify_client._models import ( + Schedule, + ScheduleCreate, + ScheduleCreateActions, + ScheduleInvoked, + ScheduleLogResponse, + ScheduleResponse, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import catch_not_found_or_throw, filter_none_values, response_to_dict +from apify_client._utils import catch_not_found_or_throw, response_to_dict from apify_client.errors import ApifyApiError @@ -42,7 +48,7 @@ def update( is_enabled: bool | None = None, is_exclusive: bool | None = None, name: str | None = None, - actions: list[dict] | None = None, + actions: list[dict[str, Any]] | None = None, description: str | None = None, timezone: str | None = None, title: str | None = None, @@ -66,19 +72,17 @@ def update( Returns: The updated schedule. """ - schedule_representation = get_schedule_repr( + request = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, name=name, - actions=actions, + actions=[ScheduleCreateActions.model_validate(a) for a in actions] if actions else None, description=description, timezone=timezone, title=title, ) - cleaned = filter_none_values(schedule_representation) - - result = self._update(cleaned) + result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data def delete(self) -> None: @@ -142,7 +146,7 @@ async def update( is_enabled: bool | None = None, is_exclusive: bool | None = None, name: str | None = None, - actions: list[dict] | None = None, + actions: list[dict[str, Any]] | None = None, description: str | None = None, timezone: str | None = None, title: str | None = None, @@ -166,19 +170,17 @@ async def update( Returns: The updated schedule. """ - schedule_representation = get_schedule_repr( + request = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, name=name, - actions=actions, + actions=[ScheduleCreateActions.model_validate(a) for a in actions] if actions else None, description=description, timezone=timezone, title=title, ) - cleaned = filter_none_values(schedule_representation) - - result = await self._update(cleaned) + result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/schedule_collection.py b/src/apify_client/_resource_clients/schedule_collection.py index a335b213..29e0d43a 100644 --- a/src/apify_client/_resource_clients/schedule_collection.py +++ b/src/apify_client/_resource_clients/schedule_collection.py @@ -3,10 +3,15 @@ from typing import Any from apify_client._docs import docs_group -from apify_client._models import ListOfSchedules, ListOfSchedulesResponse, Schedule, ScheduleResponse -from apify_client._representations import get_schedule_repr +from apify_client._models import ( + ListOfSchedules, + ListOfSchedulesResponse, + Schedule, + ScheduleCreate, + ScheduleCreateActions, + ScheduleResponse, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values @docs_group('Resource clients') @@ -50,7 +55,7 @@ def create( is_enabled: bool, is_exclusive: bool, name: str | None = None, - actions: list[dict] | None = None, # ty: ignore[invalid-type-form] + actions: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] description: str | None = None, timezone: str | None = None, title: str | None = None, @@ -77,18 +82,17 @@ def create( if not actions: actions = [] - schedule_representation = get_schedule_repr( + request = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, name=name, - actions=actions, + actions=[ScheduleCreateActions.model_validate(a) for a in actions] if actions else None, description=description, timezone=timezone, title=title, ) - - result = self._create(filter_none_values(schedule_representation)) + result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data @@ -133,7 +137,7 @@ async def create( is_enabled: bool, is_exclusive: bool, name: str | None = None, - actions: list[dict] | None = None, # ty: ignore[invalid-type-form] + actions: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form] description: str | None = None, timezone: str | None = None, title: str | None = None, @@ -160,16 +164,15 @@ async def create( if not actions: actions = [] - schedule_representation = get_schedule_repr( + request = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, name=name, - actions=actions, + actions=[ScheduleCreateActions.model_validate(a) for a in actions] if actions else None, description=description, timezone=timezone, title=title, ) - - result = await self._create(filter_none_values(schedule_representation)) + result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/task.py b/src/apify_client/_resource_clients/task.py index 4e91a7a6..7648c263 100644 --- a/src/apify_client/_resource_clients/task.py +++ b/src/apify_client/_resource_clients/task.py @@ -3,14 +3,21 @@ from typing import TYPE_CHECKING, Any from apify_client._docs import docs_group -from apify_client._models import Run, RunOrigin, RunResponse, Task, TaskResponse -from apify_client._representations import get_task_repr +from apify_client._models import ( + ActorStandby, + Run, + RunOrigin, + RunResponse, + Task, + TaskInput, + TaskOptions, + TaskResponse, + UpdateTaskRequest, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync from apify_client._utils import ( catch_not_found_or_throw, encode_webhook_list_to_base64, - enum_to_value, - filter_none_values, response_to_dict, to_seconds, ) @@ -107,24 +114,26 @@ def update( Returns: The updated task. """ - task_representation = get_task_repr( + request = UpdateTaskRequest( name=name, - task_input=task_input, - build=build, - max_items=max_items, - memory_mbytes=memory_mbytes, - timeout=timeout, - restart_on_error=restart_on_error, title=title, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, + input=TaskInput.model_validate(task_input) if task_input else None, + options=TaskOptions( + build=build, + max_items=max_items, + memory_mbytes=memory_mbytes, + timeout_secs=to_seconds(timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), ) - cleaned = filter_none_values(task_representation, remove_empty_dicts=True) - - result = self._update(cleaned) + result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data def delete(self) -> None: @@ -314,7 +323,7 @@ def last_run(self, *, status: ActorJobStatus | None = None, origin: RunOrigin | return self._client_registry.run_client( resource_id='last', resource_path='runs', - params=self._build_params(status=enum_to_value(status), origin=enum_to_value(origin)), + params=self._build_params(status=status, origin=origin), **self._base_client_kwargs, ) @@ -400,24 +409,26 @@ async def update( Returns: The updated task. """ - task_representation = get_task_repr( + request = UpdateTaskRequest( name=name, - task_input=task_input, - build=build, - max_items=max_items, - memory_mbytes=memory_mbytes, - timeout=timeout, - restart_on_error=restart_on_error, title=title, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, + input=TaskInput.model_validate(task_input) if task_input else None, + options=TaskOptions( + build=build, + max_items=max_items, + memory_mbytes=memory_mbytes, + timeout_secs=to_seconds(timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), ) - cleaned = filter_none_values(task_representation, remove_empty_dicts=True) - - result = await self._update(cleaned) + result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data async def delete(self) -> None: @@ -606,7 +617,7 @@ def last_run(self, *, status: ActorJobStatus | None = None, origin: RunOrigin | return self._client_registry.run_client( resource_id='last', resource_path='runs', - params=self._build_params(status=enum_to_value(status), origin=enum_to_value(origin)), + params=self._build_params(status=status, origin=origin), **self._base_client_kwargs, ) diff --git a/src/apify_client/_resource_clients/task_collection.py b/src/apify_client/_resource_clients/task_collection.py index b70bcae0..961753d9 100644 --- a/src/apify_client/_resource_clients/task_collection.py +++ b/src/apify_client/_resource_clients/task_collection.py @@ -3,10 +3,18 @@ from typing import TYPE_CHECKING, Any from apify_client._docs import docs_group -from apify_client._models import ListOfTasks, ListOfTasksResponse, Task, TaskResponse -from apify_client._representations import get_task_repr +from apify_client._models import ( + ActorStandby, + CreateTaskRequest, + ListOfTasks, + ListOfTasksResponse, + Task, + TaskInput, + TaskOptions, + TaskResponse, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values +from apify_client._utils import to_seconds if TYPE_CHECKING: from datetime import timedelta @@ -95,24 +103,27 @@ def create( Returns: The created task. """ - task_representation = get_task_repr( - actor_id=actor_id, + request = CreateTaskRequest( + act_id=actor_id, name=name, - task_input=task_input, - build=build, - max_items=max_items, - memory_mbytes=memory_mbytes, - timeout=timeout, - restart_on_error=restart_on_error, title=title, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, + input=TaskInput.model_validate(task_input) if task_input else None, + options=TaskOptions( + build=build, + max_items=max_items, + memory_mbytes=memory_mbytes, + timeout_secs=to_seconds(timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), ) - - result = self._create(filter_none_values(task_representation, remove_empty_dicts=True)) + result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data @@ -199,22 +210,25 @@ async def create( Returns: The created task. """ - task_representation = get_task_repr( - actor_id=actor_id, + request = CreateTaskRequest( + act_id=actor_id, name=name, - task_input=task_input, - build=build, - max_items=max_items, - memory_mbytes=memory_mbytes, - timeout=timeout, - restart_on_error=restart_on_error, title=title, - actor_standby_desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - actor_standby_max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - actor_standby_idle_timeout=actor_standby_idle_timeout, - actor_standby_build=actor_standby_build, - actor_standby_memory_mbytes=actor_standby_memory_mbytes, + input=TaskInput.model_validate(task_input) if task_input else None, + options=TaskOptions( + build=build, + max_items=max_items, + memory_mbytes=memory_mbytes, + timeout_secs=to_seconds(timeout, as_int=True), + restart_on_error=restart_on_error, + ), + actor_standby=ActorStandby( + desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, + max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, + idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), + build=actor_standby_build, + memory_mbytes=actor_standby_memory_mbytes, + ), ) - - result = await self._create(filter_none_values(task_representation, remove_empty_dicts=True)) + result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/user.py b/src/apify_client/_resource_clients/user.py index 165242f8..a30a5304 100644 --- a/src/apify_client/_resource_clients/user.py +++ b/src/apify_client/_resource_clients/user.py @@ -16,7 +16,7 @@ UserPublicInfo, ) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import catch_not_found_or_throw, filter_none_values, response_to_dict +from apify_client._utils import catch_not_found_or_throw, response_to_dict from apify_client.errors import ApifyApiError @@ -115,7 +115,7 @@ def update_limits( url=self._build_url('limits'), method='PUT', params=self._build_params(), - json=filter_none_values( + json=self._clean_json_payload( { 'maxMonthlyUsageUsd': max_monthly_usage_usd, 'dataRetentionDays': data_retention_days, @@ -219,7 +219,7 @@ async def update_limits( url=self._build_url('limits'), method='PUT', params=self._build_params(), - json=filter_none_values( + json=self._clean_json_payload( { 'maxMonthlyUsageUsd': max_monthly_usage_usd, 'dataRetentionDays': data_retention_days, diff --git a/src/apify_client/_resource_clients/webhook.py b/src/apify_client/_resource_clients/webhook.py index bb70e23f..2ba692e1 100644 --- a/src/apify_client/_resource_clients/webhook.py +++ b/src/apify_client/_resource_clients/webhook.py @@ -2,16 +2,19 @@ from typing import TYPE_CHECKING, Any +from pydantic import AnyUrl + from apify_client._docs import docs_group from apify_client._models import ( TestWebhookResponse, Webhook, + WebhookCondition, WebhookDispatch, WebhookResponse, + WebhookUpdate, ) -from apify_client._representations import get_webhook_repr from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import catch_not_found_or_throw, filter_none_values, response_to_dict +from apify_client._utils import catch_not_found_or_throw, response_to_dict from apify_client.errors import ApifyApiError if TYPE_CHECKING: @@ -78,21 +81,24 @@ def update( Returns: The updated webhook. """ - webhook_representation = get_webhook_repr( - event_types=event_types, - request_url=request_url, + if actor_run_id is not None and is_ad_hoc is None: + is_ad_hoc = True + + request = WebhookUpdate( + event_types=list(event_types) if event_types is not None else None, + request_url=AnyUrl(request_url) if request_url is not None else None, payload_template=payload_template, headers_template=headers_template, - actor_id=actor_id, - actor_task_id=actor_task_id, - actor_run_id=actor_run_id, ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, is_ad_hoc=is_ad_hoc, + condition=WebhookCondition( + actor_run_id=actor_run_id, + actor_task_id=actor_task_id, + actor_id=actor_id, + ), ) - cleaned = filter_none_values(webhook_representation, remove_empty_dicts=True) - - result = self._update(cleaned) + result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data def delete(self) -> None: @@ -200,21 +206,24 @@ async def update( Returns: The updated webhook. """ - webhook_representation = get_webhook_repr( - event_types=event_types, - request_url=request_url, + if actor_run_id is not None and is_ad_hoc is None: + is_ad_hoc = True + + request = WebhookUpdate( + event_types=list(event_types) if event_types is not None else None, + request_url=AnyUrl(request_url) if request_url is not None else None, payload_template=payload_template, headers_template=headers_template, - actor_id=actor_id, - actor_task_id=actor_task_id, - actor_run_id=actor_run_id, ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, is_ad_hoc=is_ad_hoc, + condition=WebhookCondition( + actor_run_id=actor_run_id, + actor_task_id=actor_task_id, + actor_id=actor_id, + ), ) - cleaned = filter_none_values(webhook_representation, remove_empty_dicts=True) - - result = await self._update(cleaned) + result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/webhook_collection.py b/src/apify_client/_resource_clients/webhook_collection.py index db4de310..edf90646 100644 --- a/src/apify_client/_resource_clients/webhook_collection.py +++ b/src/apify_client/_resource_clients/webhook_collection.py @@ -2,14 +2,20 @@ from typing import TYPE_CHECKING, Any +from pydantic import AnyUrl + from apify_client._docs import docs_group -from apify_client._models import ListOfWebhooks, ListOfWebhooksResponse, Webhook, WebhookResponse -from apify_client._representations import get_webhook_repr +from apify_client._models import ( + ListOfWebhooks, + ListOfWebhooksResponse, + WebhookCondition, + WebhookCreate, + WebhookResponse, +) from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync -from apify_client._utils import filter_none_values if TYPE_CHECKING: - from apify_client._models import WebhookEventType + from apify_client._models import Webhook, WebhookEventType @docs_group('Resource clients') @@ -85,21 +91,25 @@ def create( Returns: The created webhook. """ - webhook_representation = get_webhook_repr( - event_types=event_types, - request_url=request_url, + if actor_run_id is not None and is_ad_hoc is None: + is_ad_hoc = True + + request = WebhookCreate( + event_types=list(event_types), + request_url=AnyUrl(request_url), payload_template=payload_template, headers_template=headers_template, - actor_id=actor_id, - actor_task_id=actor_task_id, - actor_run_id=actor_run_id, ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, idempotency_key=idempotency_key, is_ad_hoc=is_ad_hoc, + condition=WebhookCondition( + actor_run_id=actor_run_id, + actor_task_id=actor_task_id, + actor_id=actor_id, + ), ) - - result = self._create(filter_none_values(webhook_representation, remove_empty_dicts=True)) + result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data @@ -176,19 +186,23 @@ async def create( Returns: The created webhook. """ - webhook_representation = get_webhook_repr( - event_types=event_types, - request_url=request_url, + if actor_run_id is not None and is_ad_hoc is None: + is_ad_hoc = True + + request = WebhookCreate( + event_types=list(event_types), + request_url=AnyUrl(request_url), payload_template=payload_template, headers_template=headers_template, - actor_id=actor_id, - actor_task_id=actor_task_id, - actor_run_id=actor_run_id, ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, idempotency_key=idempotency_key, is_ad_hoc=is_ad_hoc, + condition=WebhookCondition( + actor_run_id=actor_run_id, + actor_task_id=actor_task_id, + actor_id=actor_id, + ), ) - - result = await self._create(filter_none_values(webhook_representation, remove_empty_dicts=True)) + result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data diff --git a/src/apify_client/_utils.py b/src/apify_client/_utils.py index 83eb536b..3ce1a1b7 100644 --- a/src/apify_client/_utils.py +++ b/src/apify_client/_utils.py @@ -8,7 +8,6 @@ import time import warnings from base64 import b64encode, urlsafe_b64encode -from enum import Enum from http import HTTPStatus from typing import TYPE_CHECKING, Any, Literal, TypeVar, overload @@ -70,69 +69,6 @@ def catch_not_found_or_throw(exc: ApifyApiError) -> None: raise exc -def filter_none_values( - data: dict, - *, - remove_empty_dicts: bool | None = None, -) -> dict: - """Recursively remove None values from a dictionary. - - The Apify API ignores missing fields but may reject fields explicitly set to None. This helper prepares - request payloads by stripping None values from nested dictionaries. - - Uses an iterative, stack-based approach for better performance on deeply nested structures. - - Args: - data: Dictionary to clean. - remove_empty_dicts: Whether to remove empty dictionaries after filtering. - - Returns: - A new dictionary with all None values removed. - """ - # Use an explicit stack to avoid recursion overhead - result = {} - - # Stack entries are (source_dict, target_dict) - stack: list[tuple[dict, dict]] = [(data, result)] - - while stack: - source, target = stack.pop() - - for key, val in source.items(): - if val is None: - continue - - if isinstance(val, dict): - nested = {} - target[key] = nested - stack.append((val, nested)) - else: - target[key] = val - - # Optionally remove empty dictionaries - if remove_empty_dicts: - _remove_empty_dicts_inplace(result) - - return result - - -def _remove_empty_dicts_inplace(data: dict[str, Any]) -> None: - """Recursively remove empty dictionaries from a dict in place. - - This is a helper function for filter_none_values. - """ - keys_to_remove = list[str]() - - for key, val in data.items(): - if isinstance(val, dict): - _remove_empty_dicts_inplace(val) - if not val: - keys_to_remove.append(key) - - for key in keys_to_remove: - del data[key] - - def encode_webhook_list_to_base64(webhooks: list[dict]) -> str: """Encode a list of webhook dictionaries to base64 for API transmission. @@ -146,7 +82,7 @@ def encode_webhook_list_to_base64(webhooks: list[dict]) -> str: for webhook in webhooks: webhook_representation = { - 'eventTypes': [enum_to_value(event_type) for event_type in webhook['event_types']], + 'eventTypes': list(webhook['event_types']), 'requestUrl': webhook['request_url'], } if 'payload_template' in webhook: @@ -192,22 +128,6 @@ def encode_key_value_store_record_value(value: Any, content_type: str | None = N return (value, content_type) -def enum_to_value(value: Any) -> Any: - """Convert an Enum member to its value, or return the value unchanged if not an Enum. - - Ensures Enum instances are converted to primitive values suitable for API transmission. - - Args: - value: The value to potentially convert (Enum member or any other type). - - Returns: - The Enum's value if the input is an Enum; otherwise returns the input unchanged. - """ - if isinstance(value, Enum): - return value.value - return value - - def is_retryable_error(exc: Exception) -> bool: """Check if the given error is retryable. diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 4478b425..bdaef624 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,6 +1,5 @@ import io from datetime import timedelta -from enum import Enum from http import HTTPStatus from unittest.mock import Mock @@ -8,6 +7,7 @@ import pytest from apify_client._models import WebhookEventType +from apify_client._resource_clients._resource_client import ResourceClientBase from apify_client._utils import ( catch_not_found_or_throw, create_hmac_signature, @@ -15,8 +15,6 @@ encode_base62, encode_key_value_store_record_value, encode_webhook_list_to_base64, - enum_to_value, - filter_none_values, is_retryable_error, response_to_dict, response_to_list, @@ -108,22 +106,19 @@ def test_catch_not_found_or_throw(status_code: HTTPStatus, error_type: str, *, s @pytest.mark.parametrize( - ('input_dict', 'remove_empty_dicts', 'expected'), + ('input_dict', 'expected'), [ - pytest.param({'a': 1, 'b': None, 'c': 3}, False, {'a': 1, 'c': 3}, id='Simple case'), - pytest.param({'a': {'b': None, 'c': 2}, 'd': None}, False, {'a': {'c': 2}}, id='Nested dictionaries'), - pytest.param({'a': {'b': {'c': None, 'd': 4}}}, False, {'a': {'b': {'d': 4}}}, id='Deep nesting'), - pytest.param({'a': None, 'b': None}, False, {}, id='Empty dict after filtering'), - pytest.param({'a': {'b': None}, 'c': 3}, True, {'c': 3}, id='Remove empty dicts'), - pytest.param({'a': {'b': None}, 'c': 3}, False, {'a': {}, 'c': 3}, id='Keep empty dicts by default'), - pytest.param( - {'a': 0, 'b': '', 'c': False}, False, {'a': 0, 'b': '', 'c': False}, id='Keep falsy non-None values' - ), + pytest.param({'a': 1, 'b': None, 'c': 3}, {'a': 1, 'c': 3}, id='Simple case'), + pytest.param({'a': {'b': None, 'c': 2}, 'd': None}, {'a': {'c': 2}}, id='Nested dictionaries'), + pytest.param({'a': {'b': {'c': None, 'd': 4}}}, {'a': {'b': {'d': 4}}}, id='Deep nesting'), + pytest.param({'a': None, 'b': None}, {}, id='Empty dict after filtering'), + pytest.param({'a': {'b': None}, 'c': 3}, {'c': 3}, id='Remove empty dicts'), + pytest.param({'a': 0, 'b': '', 'c': False}, {'a': 0, 'b': '', 'c': False}, id='Keep falsy non-None values'), ], ) -def test_filter_none_values(input_dict: dict, *, remove_empty_dicts: bool, expected: dict) -> None: - """Test filtering None values from dictionaries.""" - assert filter_none_values(input_dict, remove_empty_dicts=remove_empty_dicts) == expected +def test__clean_json_payload(input_dict: dict, expected: dict) -> None: + """Test cleaning None values and empty dicts from API request payloads.""" + assert ResourceClientBase._clean_json_payload(input_dict) == expected def test_encode_key_value_store_record_value_dict() -> None: @@ -162,26 +157,6 @@ def test_encode_key_value_store_record_value_bytesio() -> None: assert content_type == 'application/octet-stream' -class _TestEnum(Enum): - VALUE1 = 'val1' - VALUE2 = 42 - - -@pytest.mark.parametrize( - ('input_value', 'expected'), - [ - pytest.param(_TestEnum.VALUE1, 'val1', id='Enum string value'), - pytest.param(_TestEnum.VALUE2, 42, id='Enum int value'), - pytest.param('not_an_enum', 'not_an_enum', id='Plain string passthrough'), - pytest.param(123, 123, id='Plain int passthrough'), - pytest.param(None, None, id='None passthrough'), - ], -) -def test_enum_to_value(input_value: _TestEnum | str | int | None, expected: str | int | None) -> None: - """Test enum to value conversion.""" - assert enum_to_value(input_value) == expected - - def test_response_to_dict() -> None: """Test parsing response as dictionary.""" mock_response = Mock() From 36d710a49360701c54f81734600397ecea72b1f0 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Fri, 27 Feb 2026 10:09:51 +0100 Subject: [PATCH 3/5] Fix models --- src/apify_client/_models.py | 91 +++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/src/apify_client/_models.py b/src/apify_client/_models.py index fd55b903..4b7d1971 100644 --- a/src/apify_client/_models.py +++ b/src/apify_client/_models.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: https://docs.apify.com/api/openapi.json -# timestamp: 2026-02-27T09:05:36+00:00 +# timestamp: 2026-02-24T14:39:16+00:00 from __future__ import annotations @@ -276,15 +276,48 @@ class FreeActorPricingInfo(CommonActorPricingInfo): pricing_model: Annotated[Literal['FREE'], Field(alias='pricingModel')] +class ActorPermissionLevel(StrEnum): + """Determines permissions that the Actor requires to run. For more information, see the [Actor permissions documentation](https://docs.apify.com/platform/actors/development/permissions).""" + + LIMITED_PERMISSIONS = 'LIMITED_PERMISSIONS' + FULL_PERMISSIONS = 'FULL_PERMISSIONS' + + class DefaultRunOptions(BaseModel): model_config = ConfigDict( extra='allow', populate_by_name=True, ) - build: Annotated[str, Field(examples=['latest'])] + build: Annotated[str | None, Field(examples=['latest'])] = None timeout_secs: Annotated[int | None, Field(alias='timeoutSecs', examples=[3600])] = None - memory_mbytes: Annotated[int, Field(alias='memoryMbytes', examples=[2048])] + memory_mbytes: Annotated[int | None, Field(alias='memoryMbytes', examples=[2048])] = None restart_on_error: Annotated[bool | None, Field(alias='restartOnError', examples=[False])] = None + max_items: Annotated[int | None, Field(alias='maxItems')] = None + force_permission_level: Annotated[ActorPermissionLevel | None, Field(alias='forcePermissionLevel')] = None + + +class ActorStandby(BaseModel): + model_config = ConfigDict( + extra='allow', + populate_by_name=True, + ) + is_enabled: Annotated[bool | None, Field(alias='isEnabled')] = None + desired_requests_per_actor_run: Annotated[int | None, Field(alias='desiredRequestsPerActorRun')] = None + max_requests_per_actor_run: Annotated[int | None, Field(alias='maxRequestsPerActorRun')] = None + idle_timeout_secs: Annotated[int | None, Field(alias='idleTimeoutSecs')] = None + build: str | None = None + memory_mbytes: Annotated[int | None, Field(alias='memoryMbytes')] = None + disable_standby_fields_override: Annotated[bool | None, Field(alias='disableStandbyFieldsOverride')] = None + should_pass_actor_input: Annotated[bool | None, Field(alias='shouldPassActorInput')] = None + + +class ExampleRunInput(BaseModel): + model_config = ConfigDict( + extra='allow', + populate_by_name=True, + ) + body: Annotated[str | None, Field(examples=['{ "helloWorld": 123 }'])] = None + content_type: Annotated[str | None, Field(alias='contentType', examples=['application/json; charset=utf-8'])] = None class CreateActorRequest(BaseModel): @@ -312,22 +345,9 @@ class CreateActorRequest(BaseModel): ] = None categories: list[str] | None = None default_run_options: Annotated[DefaultRunOptions | None, Field(alias='defaultRunOptions')] = None - - -class ActorPermissionLevel(StrEnum): - """Determines permissions that the Actor requires to run. For more information, see the [Actor permissions documentation](https://docs.apify.com/platform/actors/development/permissions).""" - - LIMITED_PERMISSIONS = 'LIMITED_PERMISSIONS' - FULL_PERMISSIONS = 'FULL_PERMISSIONS' - - -class ExampleRunInput(BaseModel): - model_config = ConfigDict( - extra='allow', - populate_by_name=True, - ) - body: Annotated[str, Field(examples=['{ "helloWorld": 123 }'])] - content_type: Annotated[str, Field(alias='contentType', examples=['application/json; charset=utf-8'])] + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None + example_run_input: Annotated[ExampleRunInput | None, Field(alias='exampleRunInput')] = None + is_deprecated: Annotated[bool | None, Field(alias='isDeprecated')] = None class TaggedBuildInfo(BaseModel): @@ -390,6 +410,7 @@ class Actor(BaseModel): """ A brief, LLM-generated readme summary """ + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None class ActorResponse(BaseModel): @@ -442,15 +463,15 @@ class UpdateActorRequest(BaseModel): extra='allow', populate_by_name=True, ) - name: Annotated[str, Field(examples=['MyActor'])] + name: Annotated[str | None, Field(examples=['MyActor'])] = None description: Annotated[str | None, Field(examples=['My favourite actor!'])] = None - is_public: Annotated[bool, Field(alias='isPublic', examples=[False])] + is_public: Annotated[bool | None, Field(alias='isPublic', examples=[False])] = None actor_permission_level: Annotated[ActorPermissionLevel | None, Field(alias='actorPermissionLevel')] = None seo_title: Annotated[str | None, Field(alias='seoTitle', examples=['My actor'])] = None seo_description: Annotated[str | None, Field(alias='seoDescription', examples=['My actor is the best'])] = None title: Annotated[str | None, Field(examples=['My Actor'])] = None restart_on_error: Annotated[bool | None, Field(alias='restartOnError', examples=[False])] = None - versions: list[CreateOrUpdateVersionRequest] + versions: list[CreateOrUpdateVersionRequest] | None = None pricing_infos: Annotated[ list[ PayPerEventActorPricingInfo @@ -508,6 +529,9 @@ class UpdateActorRequest(BaseModel): ``` """ + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None + example_run_input: Annotated[ExampleRunInput | None, Field(alias='exampleRunInput')] = None + is_deprecated: Annotated[bool | None, Field(alias='isDeprecated')] = None class ListOfVersions(BaseModel): @@ -601,9 +625,7 @@ class ExampleWebhookDispatch(BaseModel): populate_by_name=True, ) status: WebhookDispatchStatus - finished_at: Annotated[AwareDatetime | None, Field(alias='finishedAt', examples=['2019-12-13T08:36:13.202Z'])] = ( - None - ) + finished_at: Annotated[AwareDatetime, Field(alias='finishedAt', examples=['2019-12-13T08:36:13.202Z'])] class WebhookStats(BaseModel): @@ -1244,6 +1266,7 @@ class TaskOptions(BaseModel): timeout_secs: Annotated[int | None, Field(alias='timeoutSecs', examples=[300])] = None memory_mbytes: Annotated[int | None, Field(alias='memoryMbytes', examples=[128])] = None restart_on_error: Annotated[bool | None, Field(alias='restartOnError', examples=[False])] = None + max_items: Annotated[int | None, Field(alias='maxItems')] = None class TaskInput(BaseModel): @@ -1267,6 +1290,8 @@ class CreateTaskRequest(BaseModel): name: Annotated[str, Field(examples=['my-task'])] options: TaskOptions | None = None input: TaskInput | None = None + title: str | None = None + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None class Task(BaseModel): @@ -1286,6 +1311,8 @@ class Task(BaseModel): options: TaskOptions | None = None input: TaskInput | None = None standby_url: Annotated[AnyUrl | None, Field(alias='standbyUrl')] = None + title: str | None = None + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None class TaskResponse(BaseModel): @@ -1303,17 +1330,11 @@ class UpdateTaskRequest(BaseModel): extra='allow', populate_by_name=True, ) - id: Annotated[str, Field(examples=['ZxLNxrRaZrSjuhT9y'])] - user_id: Annotated[str, Field(alias='userId', examples=['BPWZBd7Z9c746JAnF'])] - act_id: Annotated[str, Field(alias='actId', examples=['asADASadYvn4mBZmm'])] - name: Annotated[str, Field(examples=['my-task'])] - username: Annotated[str | None, Field(examples=['janedoe'])] = None - created_at: Annotated[AwareDatetime, Field(alias='createdAt', examples=['2018-10-26T07:23:14.855Z'])] - modified_at: Annotated[AwareDatetime, Field(alias='modifiedAt', examples=['2018-10-26T13:30:49.578Z'])] - removed_at: Annotated[AwareDatetime | None, Field(alias='removedAt')] = None - stats: TaskStats | None = None + name: Annotated[str | None, Field(examples=['my-task'])] = None + title: str | None = None options: TaskOptions | None = None input: TaskInput | None = None + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None class Webhook(BaseModel): @@ -2655,6 +2676,7 @@ class ScheduleCreate(BaseModel): cron_expression: Annotated[str | None, Field(alias='cronExpression', examples=['* * * * *'])] = None timezone: Annotated[str | None, Field(examples=['UTC'])] = None description: Annotated[str | None, Field(examples=['Schedule of actor ...'])] = None + title: str | None = None actions: list[ScheduleCreateActions] | None = None @@ -2687,6 +2709,7 @@ class Schedule(BaseModel): modified_at: Annotated[AwareDatetime, Field(alias='modifiedAt', examples=['2019-12-20T06:33:11.202Z'])] next_run_at: Annotated[AwareDatetime | None, Field(alias='nextRunAt', examples=['2019-04-12T07:34:10.202Z'])] = None last_run_at: Annotated[AwareDatetime | None, Field(alias='lastRunAt', examples=['2019-04-12T07:33:10.202Z'])] = None + title: str | None = None actions: list[ScheduleActions] From 7b6af16dede8f1ab8ef86deaf6ff8d0a9dce81d7 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Fri, 27 Feb 2026 10:48:59 +0100 Subject: [PATCH 4/5] regenerate models --- src/apify_client/_models.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/apify_client/_models.py b/src/apify_client/_models.py index 4b7d1971..9adc8ee8 100644 --- a/src/apify_client/_models.py +++ b/src/apify_client/_models.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: https://docs.apify.com/api/openapi.json -# timestamp: 2026-02-24T14:39:16+00:00 +# timestamp: 2026-02-27T09:48:14+00:00 from __future__ import annotations @@ -406,11 +406,11 @@ class Actor(BaseModel): deployment_key: Annotated[str | None, Field(alias='deploymentKey', examples=['ssh-rsa AAAA ...'])] = None title: Annotated[str | None, Field(examples=['My Actor'])] = None tagged_builds: Annotated[dict[str, TaggedBuildInfo | None] | None, Field(alias='taggedBuilds')] = None + actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None readme_summary: Annotated[str | None, Field(alias='readmeSummary')] = None """ A brief, LLM-generated readme summary """ - actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None class ActorResponse(BaseModel): @@ -625,7 +625,9 @@ class ExampleWebhookDispatch(BaseModel): populate_by_name=True, ) status: WebhookDispatchStatus - finished_at: Annotated[AwareDatetime, Field(alias='finishedAt', examples=['2019-12-13T08:36:13.202Z'])] + finished_at: Annotated[AwareDatetime | None, Field(alias='finishedAt', examples=['2019-12-13T08:36:13.202Z'])] = ( + None + ) class WebhookStats(BaseModel): @@ -1310,9 +1312,9 @@ class Task(BaseModel): stats: TaskStats | None = None options: TaskOptions | None = None input: TaskInput | None = None - standby_url: Annotated[AnyUrl | None, Field(alias='standbyUrl')] = None title: str | None = None actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None + standby_url: Annotated[AnyUrl | None, Field(alias='standbyUrl')] = None class TaskResponse(BaseModel): @@ -1331,9 +1333,9 @@ class UpdateTaskRequest(BaseModel): populate_by_name=True, ) name: Annotated[str | None, Field(examples=['my-task'])] = None - title: str | None = None options: TaskOptions | None = None input: TaskInput | None = None + title: str | None = None actor_standby: Annotated[ActorStandby | None, Field(alias='actorStandby')] = None From f2133a49ba11e8d65054f6de075ca5de44b6cc0b Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Fri, 27 Feb 2026 19:43:35 +0100 Subject: [PATCH 5/5] address feedback --- src/apify_client/_resource_clients/actor.py | 8 ++++---- .../_resource_clients/actor_collection.py | 8 ++++---- .../_resource_clients/actor_version.py | 8 ++++---- .../actor_version_collection.py | 8 ++++---- src/apify_client/_resource_clients/schedule.py | 8 ++++---- .../_resource_clients/schedule_collection.py | 8 ++++---- src/apify_client/_resource_clients/task.py | 8 ++++---- .../_resource_clients/task_collection.py | 8 ++++---- src/apify_client/_resource_clients/webhook.py | 18 ++++++------------ .../_resource_clients/webhook_collection.py | 18 ++++++------------ 10 files changed, 44 insertions(+), 56 deletions(-) diff --git a/src/apify_client/_resource_clients/actor.py b/src/apify_client/_resource_clients/actor.py index 45b3c370..09d80e66 100644 --- a/src/apify_client/_resource_clients/actor.py +++ b/src/apify_client/_resource_clients/actor.py @@ -168,7 +168,7 @@ def update( Returns: The updated Actor. """ - request = UpdateActorRequest( + actor_fields = UpdateActorRequest( name=name, title=title, description=description, @@ -201,7 +201,7 @@ def update( ), tagged_builds=tagged_builds, ) - result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._update(**actor_fields.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data def delete(self) -> None: @@ -633,7 +633,7 @@ async def update( Returns: The updated Actor. """ - request = UpdateActorRequest( + actor_fields = UpdateActorRequest( name=name, title=title, description=description, @@ -666,7 +666,7 @@ async def update( ), tagged_builds=tagged_builds, ) - result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._update(**actor_fields.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/actor_collection.py b/src/apify_client/_resource_clients/actor_collection.py index 1ea01ea8..22ccaafb 100644 --- a/src/apify_client/_resource_clients/actor_collection.py +++ b/src/apify_client/_resource_clients/actor_collection.py @@ -120,7 +120,7 @@ def create( Returns: The created Actor. """ - request = CreateActorRequest( + actor_fields = CreateActorRequest( name=name, title=title, description=description, @@ -150,7 +150,7 @@ def create( content_type=example_run_input_content_type, ), ) - result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._create(**actor_fields.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data @@ -254,7 +254,7 @@ async def create( Returns: The created Actor. """ - request = CreateActorRequest( + actor_fields = CreateActorRequest( name=name, title=title, description=description, @@ -284,5 +284,5 @@ async def create( content_type=example_run_input_content_type, ), ) - result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._create(**actor_fields.model_dump(by_alias=True, exclude_none=True)) return ActorResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/actor_version.py b/src/apify_client/_resource_clients/actor_version.py index 9fac9ba7..bfd6982d 100644 --- a/src/apify_client/_resource_clients/actor_version.py +++ b/src/apify_client/_resource_clients/actor_version.py @@ -96,7 +96,7 @@ def update( Returns: The updated Actor version. """ - request = CreateOrUpdateVersionRequest( + version_fields = CreateOrUpdateVersionRequest( build_tag=build_tag, env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, apply_env_vars_to_build=apply_env_vars_to_build, @@ -106,7 +106,7 @@ def update( tarball_url=tarball_url, github_gist_url=github_gist_url, ) - result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._update(**version_fields.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data def delete(self) -> None: @@ -204,7 +204,7 @@ async def update( Returns: The updated Actor version. """ - request = CreateOrUpdateVersionRequest( + version_fields = CreateOrUpdateVersionRequest( build_tag=build_tag, env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, apply_env_vars_to_build=apply_env_vars_to_build, @@ -214,7 +214,7 @@ async def update( tarball_url=tarball_url, github_gist_url=github_gist_url, ) - result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._update(**version_fields.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/actor_version_collection.py b/src/apify_client/_resource_clients/actor_version_collection.py index edecd406..04de02b8 100644 --- a/src/apify_client/_resource_clients/actor_version_collection.py +++ b/src/apify_client/_resource_clients/actor_version_collection.py @@ -81,7 +81,7 @@ def create( Returns: The created Actor version. """ - request = CreateOrUpdateVersionRequest( + version_fields = CreateOrUpdateVersionRequest( version_number=version_number, build_tag=build_tag, env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, @@ -92,7 +92,7 @@ def create( tarball_url=tarball_url, github_gist_url=github_gist_url, ) - result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._create(**version_fields.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data @@ -156,7 +156,7 @@ async def create( Returns: The created Actor version. """ - request = CreateOrUpdateVersionRequest( + version_fields = CreateOrUpdateVersionRequest( version_number=version_number, build_tag=build_tag, env_vars=[EnvVar.model_validate(v) for v in env_vars] if env_vars else None, @@ -167,5 +167,5 @@ async def create( tarball_url=tarball_url, github_gist_url=github_gist_url, ) - result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._create(**version_fields.model_dump(by_alias=True, exclude_none=True)) return VersionResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/schedule.py b/src/apify_client/_resource_clients/schedule.py index 800ce0d4..1aba49b3 100644 --- a/src/apify_client/_resource_clients/schedule.py +++ b/src/apify_client/_resource_clients/schedule.py @@ -72,7 +72,7 @@ def update( Returns: The updated schedule. """ - request = ScheduleCreate( + schedule_fields = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, @@ -82,7 +82,7 @@ def update( timezone=timezone, title=title, ) - result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._update(**schedule_fields.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data def delete(self) -> None: @@ -170,7 +170,7 @@ async def update( Returns: The updated schedule. """ - request = ScheduleCreate( + schedule_fields = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, @@ -180,7 +180,7 @@ async def update( timezone=timezone, title=title, ) - result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._update(**schedule_fields.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/schedule_collection.py b/src/apify_client/_resource_clients/schedule_collection.py index 29e0d43a..d00086c6 100644 --- a/src/apify_client/_resource_clients/schedule_collection.py +++ b/src/apify_client/_resource_clients/schedule_collection.py @@ -82,7 +82,7 @@ def create( if not actions: actions = [] - request = ScheduleCreate( + schedule_fields = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, @@ -92,7 +92,7 @@ def create( timezone=timezone, title=title, ) - result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._create(**schedule_fields.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data @@ -164,7 +164,7 @@ async def create( if not actions: actions = [] - request = ScheduleCreate( + schedule_fields = ScheduleCreate( cron_expression=cron_expression, is_enabled=is_enabled, is_exclusive=is_exclusive, @@ -174,5 +174,5 @@ async def create( timezone=timezone, title=title, ) - result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._create(**schedule_fields.model_dump(by_alias=True, exclude_none=True)) return ScheduleResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/task.py b/src/apify_client/_resource_clients/task.py index 7648c263..eeb6ba6d 100644 --- a/src/apify_client/_resource_clients/task.py +++ b/src/apify_client/_resource_clients/task.py @@ -114,7 +114,7 @@ def update( Returns: The updated task. """ - request = UpdateTaskRequest( + task_fields = UpdateTaskRequest( name=name, title=title, input=TaskInput.model_validate(task_input) if task_input else None, @@ -133,7 +133,7 @@ def update( memory_mbytes=actor_standby_memory_mbytes, ), ) - result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._update(**task_fields.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data def delete(self) -> None: @@ -409,7 +409,7 @@ async def update( Returns: The updated task. """ - request = UpdateTaskRequest( + task_fields = UpdateTaskRequest( name=name, title=title, input=TaskInput.model_validate(task_input) if task_input else None, @@ -428,7 +428,7 @@ async def update( memory_mbytes=actor_standby_memory_mbytes, ), ) - result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._update(**task_fields.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/task_collection.py b/src/apify_client/_resource_clients/task_collection.py index 961753d9..5384f71c 100644 --- a/src/apify_client/_resource_clients/task_collection.py +++ b/src/apify_client/_resource_clients/task_collection.py @@ -103,7 +103,7 @@ def create( Returns: The created task. """ - request = CreateTaskRequest( + task_fields = CreateTaskRequest( act_id=actor_id, name=name, title=title, @@ -123,7 +123,7 @@ def create( memory_mbytes=actor_standby_memory_mbytes, ), ) - result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._create(**task_fields.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data @@ -210,7 +210,7 @@ async def create( Returns: The created task. """ - request = CreateTaskRequest( + task_fields = CreateTaskRequest( act_id=actor_id, name=name, title=title, @@ -230,5 +230,5 @@ async def create( memory_mbytes=actor_standby_memory_mbytes, ), ) - result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._create(**task_fields.model_dump(by_alias=True, exclude_none=True)) return TaskResponse.model_validate(result).data diff --git a/src/apify_client/_resource_clients/webhook.py b/src/apify_client/_resource_clients/webhook.py index 2ba692e1..7a4e806d 100644 --- a/src/apify_client/_resource_clients/webhook.py +++ b/src/apify_client/_resource_clients/webhook.py @@ -81,24 +81,21 @@ def update( Returns: The updated webhook. """ - if actor_run_id is not None and is_ad_hoc is None: - is_ad_hoc = True - - request = WebhookUpdate( + webhook_update = WebhookUpdate( event_types=list(event_types) if event_types is not None else None, request_url=AnyUrl(request_url) if request_url is not None else None, payload_template=payload_template, headers_template=headers_template, ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, - is_ad_hoc=is_ad_hoc, + is_ad_hoc=is_ad_hoc if actor_run_id else None, condition=WebhookCondition( actor_run_id=actor_run_id, actor_task_id=actor_task_id, actor_id=actor_id, ), ) - result = self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._update(**webhook_update.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data def delete(self) -> None: @@ -206,24 +203,21 @@ async def update( Returns: The updated webhook. """ - if actor_run_id is not None and is_ad_hoc is None: - is_ad_hoc = True - - request = WebhookUpdate( + webhook_update = WebhookUpdate( event_types=list(event_types) if event_types is not None else None, request_url=AnyUrl(request_url) if request_url is not None else None, payload_template=payload_template, headers_template=headers_template, ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, - is_ad_hoc=is_ad_hoc, + is_ad_hoc=is_ad_hoc if actor_run_id else None, condition=WebhookCondition( actor_run_id=actor_run_id, actor_task_id=actor_task_id, actor_id=actor_id, ), ) - result = await self._update(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._update(**webhook_update.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data async def delete(self) -> None: diff --git a/src/apify_client/_resource_clients/webhook_collection.py b/src/apify_client/_resource_clients/webhook_collection.py index edf90646..9a3104b1 100644 --- a/src/apify_client/_resource_clients/webhook_collection.py +++ b/src/apify_client/_resource_clients/webhook_collection.py @@ -91,10 +91,7 @@ def create( Returns: The created webhook. """ - if actor_run_id is not None and is_ad_hoc is None: - is_ad_hoc = True - - request = WebhookCreate( + webhook_create = WebhookCreate( event_types=list(event_types), request_url=AnyUrl(request_url), payload_template=payload_template, @@ -102,14 +99,14 @@ def create( ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, idempotency_key=idempotency_key, - is_ad_hoc=is_ad_hoc, + is_ad_hoc=is_ad_hoc if actor_run_id else None, condition=WebhookCondition( actor_run_id=actor_run_id, actor_task_id=actor_task_id, actor_id=actor_id, ), ) - result = self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = self._create(**webhook_create.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data @@ -186,10 +183,7 @@ async def create( Returns: The created webhook. """ - if actor_run_id is not None and is_ad_hoc is None: - is_ad_hoc = True - - request = WebhookCreate( + webhook_create = WebhookCreate( event_types=list(event_types), request_url=AnyUrl(request_url), payload_template=payload_template, @@ -197,12 +191,12 @@ async def create( ignore_ssl_errors=ignore_ssl_errors, do_not_retry=do_not_retry, idempotency_key=idempotency_key, - is_ad_hoc=is_ad_hoc, + is_ad_hoc=is_ad_hoc if actor_run_id else None, condition=WebhookCondition( actor_run_id=actor_run_id, actor_task_id=actor_task_id, actor_id=actor_id, ), ) - result = await self._create(**request.model_dump(by_alias=True, exclude_none=True)) + result = await self._create(**webhook_create.model_dump(by_alias=True, exclude_none=True)) return WebhookResponse.model_validate(result).data