Skip to content

Commit c338062

Browse files
committed
Use resource client registry
1 parent d1a59c3 commit c338062

File tree

10 files changed

+652
-592
lines changed

10 files changed

+652
-592
lines changed

src/apify_client/_apify_client.py

Lines changed: 101 additions & 48 deletions
Large diffs are not rendered by default.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""Client classes configuration for dependency injection."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from apify_client._resource_clients import (
10+
ActorClient,
11+
ActorClientAsync,
12+
ActorEnvVarClient,
13+
ActorEnvVarClientAsync,
14+
ActorEnvVarCollectionClient,
15+
ActorEnvVarCollectionClientAsync,
16+
ActorVersionClient,
17+
ActorVersionClientAsync,
18+
ActorVersionCollectionClient,
19+
ActorVersionCollectionClientAsync,
20+
BuildClient,
21+
BuildClientAsync,
22+
BuildCollectionClient,
23+
BuildCollectionClientAsync,
24+
DatasetClient,
25+
DatasetClientAsync,
26+
KeyValueStoreClient,
27+
KeyValueStoreClientAsync,
28+
LogClient,
29+
LogClientAsync,
30+
RequestQueueClient,
31+
RequestQueueClientAsync,
32+
RunClient,
33+
RunClientAsync,
34+
RunCollectionClient,
35+
RunCollectionClientAsync,
36+
WebhookClient,
37+
WebhookClientAsync,
38+
WebhookCollectionClient,
39+
WebhookCollectionClientAsync,
40+
WebhookDispatchCollectionClient,
41+
WebhookDispatchCollectionClientAsync,
42+
)
43+
44+
45+
@dataclass
46+
class ClientRegistry:
47+
"""Bundle of all sync client classes for dependency injection.
48+
49+
This config object is passed through the client hierarchy to avoid
50+
parameter explosion when clients need to create other clients.
51+
Each resource client receives this config and can instantiate other
52+
clients as needed without knowing about transitive dependencies.
53+
"""
54+
55+
# Actor-related
56+
actor_client: type[ActorClient]
57+
actor_version_client: type[ActorVersionClient]
58+
actor_version_collection_client: type[ActorVersionCollectionClient]
59+
actor_env_var_client: type[ActorEnvVarClient]
60+
actor_env_var_collection_client: type[ActorEnvVarCollectionClient]
61+
62+
# Build-related
63+
build_client: type[BuildClient]
64+
build_collection_client: type[BuildCollectionClient]
65+
66+
# Run-related
67+
run_client: type[RunClient]
68+
run_collection_client: type[RunCollectionClient]
69+
70+
# Storage-related
71+
dataset_client: type[DatasetClient]
72+
key_value_store_client: type[KeyValueStoreClient]
73+
request_queue_client: type[RequestQueueClient]
74+
75+
# Webhook-related
76+
webhook_client: type[WebhookClient]
77+
webhook_collection_client: type[WebhookCollectionClient]
78+
webhook_dispatch_collection_client: type[WebhookDispatchCollectionClient]
79+
80+
# Utilities
81+
log_client: type[LogClient]
82+
83+
84+
@dataclass
85+
class ClientRegistryAsync:
86+
"""Bundle of all async client classes for dependency injection.
87+
88+
Async version of ClientRegistry for use with ApifyClientAsync.
89+
"""
90+
91+
# Actor-related
92+
actor_client: type[ActorClientAsync]
93+
actor_version_client: type[ActorVersionClientAsync]
94+
actor_version_collection_client: type[ActorVersionCollectionClientAsync]
95+
actor_env_var_client: type[ActorEnvVarClientAsync]
96+
actor_env_var_collection_client: type[ActorEnvVarCollectionClientAsync]
97+
98+
# Build-related
99+
build_client: type[BuildClientAsync]
100+
build_collection_client: type[BuildCollectionClientAsync]
101+
102+
# Run-related
103+
run_client: type[RunClientAsync]
104+
run_collection_client: type[RunCollectionClientAsync]
105+
106+
# Storage-related
107+
dataset_client: type[DatasetClientAsync]
108+
key_value_store_client: type[KeyValueStoreClientAsync]
109+
request_queue_client: type[RequestQueueClientAsync]
110+
111+
# Webhook-related
112+
webhook_client: type[WebhookClientAsync]
113+
webhook_collection_client: type[WebhookCollectionClientAsync]
114+
webhook_dispatch_collection_client: type[WebhookDispatchCollectionClientAsync]
115+
116+
# Utilities
117+
log_client: type[LogClientAsync]

0 commit comments

Comments
 (0)