s-librarykit 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- librarykit/__init__.py +238 -0
- librarykit/antibot.py +467 -0
- librarykit/auth.py +423 -0
- librarykit/browser.py +722 -0
- librarykit/checkpoint.py +187 -0
- librarykit/config_util.py +281 -0
- librarykit/contract.py +376 -0
- librarykit/entities.py +151 -0
- librarykit/enums.py +42 -0
- librarykit/errmap.py +352 -0
- librarykit/errors.py +261 -0
- librarykit/orchestration/__init__.py +43 -0
- librarykit/orchestration/health.py +308 -0
- librarykit/orchestration/onboarding.py +428 -0
- librarykit/orchestration/session_loader.py +121 -0
- librarykit/pagination.py +368 -0
- librarykit/ports.py +95 -0
- librarykit/protocols.py +183 -0
- librarykit/retry.py +287 -0
- librarykit/rpc.py +191 -0
- librarykit/secret_store.py +184 -0
- librarykit/sessions.py +811 -0
- librarykit/stream.py +166 -0
- librarykit/transport.py +738 -0
- s_librarykit-0.1.0.dist-info/METADATA +84 -0
- s_librarykit-0.1.0.dist-info/RECORD +28 -0
- s_librarykit-0.1.0.dist-info/WHEEL +4 -0
- s_librarykit-0.1.0.dist-info/licenses/LICENSE +21 -0
librarykit/__init__.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""librarykit — жирный КОРЕНЬ китов (граф librarykit <- adapterkit <- clikit).
|
|
2
|
+
|
|
3
|
+
Общий код вместо дублирования в clikit/adapterkit/reverse-factory: единая
|
|
4
|
+
error-иерархия (ERROR-HUB), config/paths-утили, политики повторов, checkpoint.
|
|
5
|
+
Почти-stdlib (единственная не-stdlib зависимость — platformdirs для AppPaths).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from librarykit.auth import (
|
|
11
|
+
BrowserLoginAuth,
|
|
12
|
+
CookieSessionAuth,
|
|
13
|
+
OAuth2Auth,
|
|
14
|
+
TokenAuth,
|
|
15
|
+
decrypt_settings,
|
|
16
|
+
dump_settings,
|
|
17
|
+
encrypt_settings,
|
|
18
|
+
load_settings,
|
|
19
|
+
)
|
|
20
|
+
from librarykit.checkpoint import Checkpoint, JsonlSink, RunMetrics
|
|
21
|
+
from librarykit.config_util import (
|
|
22
|
+
AppPaths,
|
|
23
|
+
atomic_write_text,
|
|
24
|
+
chmod_600,
|
|
25
|
+
deep_merge,
|
|
26
|
+
interpolate_env,
|
|
27
|
+
load_dotenv,
|
|
28
|
+
normalize_account_id,
|
|
29
|
+
slugify,
|
|
30
|
+
)
|
|
31
|
+
from librarykit.contract import (
|
|
32
|
+
Auth,
|
|
33
|
+
AuthMode,
|
|
34
|
+
Codec,
|
|
35
|
+
Creds,
|
|
36
|
+
ErrorMapper,
|
|
37
|
+
PaginationMode,
|
|
38
|
+
Paginator,
|
|
39
|
+
Refreshable,
|
|
40
|
+
RequestBody,
|
|
41
|
+
ResponseLike,
|
|
42
|
+
SessionRef,
|
|
43
|
+
SessionStoreProtocol,
|
|
44
|
+
StreamTransport,
|
|
45
|
+
Transport,
|
|
46
|
+
TransportKind,
|
|
47
|
+
)
|
|
48
|
+
from librarykit.entities import (
|
|
49
|
+
HealthReport,
|
|
50
|
+
Session,
|
|
51
|
+
SessionChanges,
|
|
52
|
+
SessionContext,
|
|
53
|
+
)
|
|
54
|
+
from librarykit.errmap import (
|
|
55
|
+
DEFAULT_ERROR_MAP,
|
|
56
|
+
AuthExpired,
|
|
57
|
+
BodyRule,
|
|
58
|
+
ErrorMap,
|
|
59
|
+
ErrorMapBuilder,
|
|
60
|
+
ExcFactory,
|
|
61
|
+
build_error_map,
|
|
62
|
+
)
|
|
63
|
+
from librarykit.errors import (
|
|
64
|
+
RETRYABLE,
|
|
65
|
+
AdapterError,
|
|
66
|
+
ApiError,
|
|
67
|
+
AuthRequired,
|
|
68
|
+
Blocked,
|
|
69
|
+
CliError,
|
|
70
|
+
NotFound,
|
|
71
|
+
NotFoundError,
|
|
72
|
+
NotImplementedYet,
|
|
73
|
+
RateLimited,
|
|
74
|
+
ServerError,
|
|
75
|
+
SessionExpired,
|
|
76
|
+
TransportError,
|
|
77
|
+
ValidationError,
|
|
78
|
+
)
|
|
79
|
+
from librarykit.pagination import (
|
|
80
|
+
DEFAULT_PAGE_PARAMS,
|
|
81
|
+
CursorExtractor,
|
|
82
|
+
CursorPaginator,
|
|
83
|
+
ItemsExtractor,
|
|
84
|
+
PageParams,
|
|
85
|
+
default_extract_cursor,
|
|
86
|
+
default_extract_items,
|
|
87
|
+
with_page_params,
|
|
88
|
+
)
|
|
89
|
+
from librarykit.protocols import (
|
|
90
|
+
HealthProtocol,
|
|
91
|
+
HealthState,
|
|
92
|
+
HealthStatus,
|
|
93
|
+
InteractiveFlow,
|
|
94
|
+
LoginMode,
|
|
95
|
+
LoginRequirements,
|
|
96
|
+
OnboardingProtocol,
|
|
97
|
+
)
|
|
98
|
+
from librarykit.retry import (
|
|
99
|
+
DEFAULT_RETRY,
|
|
100
|
+
DEFAULT_SIMPLE_RETRY,
|
|
101
|
+
RetryPolicy,
|
|
102
|
+
SimpleRetryPolicy,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Мультипротокол (E1): RPC codec-слой (rpc) + stream-транспорты (stream). WS-
|
|
106
|
+
# reference (`WebSocketsStreamTransport`) тянет extra [ws] lazy ВНУТРИ конструктора,
|
|
107
|
+
# поэтому реэкспорт безопасен — `import librarykit` без extra не падает.
|
|
108
|
+
from librarykit.rpc import JsonCodec, PrefixedJsonCodec, RpcClient
|
|
109
|
+
from librarykit.secret_store import SecretStore
|
|
110
|
+
from librarykit.sessions import (
|
|
111
|
+
KekUnavailableError,
|
|
112
|
+
SessionStore,
|
|
113
|
+
SessionStoreError,
|
|
114
|
+
resolve_kek,
|
|
115
|
+
)
|
|
116
|
+
from librarykit.stream import (
|
|
117
|
+
StreamClosedError,
|
|
118
|
+
StubStreamTransport,
|
|
119
|
+
WebSocketsStreamTransport,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
# Транспортный слой (W4): choke-point `HttpClient` + конкретный `HttpxTransport`.
|
|
123
|
+
# `RestHttpClient`/`ApiError`/`RefreshCallback` НЕ ре-экспортируются на верхний
|
|
124
|
+
# уровень — у librarykit.errors уже есть свой `ApiError` (алиас CliError), и REST-
|
|
125
|
+
# клиент берётся адресно из `librarykit.transport` (его тянет shim clikit.transport).
|
|
126
|
+
from librarykit.transport import HttpClient, HttpxTransport
|
|
127
|
+
|
|
128
|
+
__version__ = "0.1.0"
|
|
129
|
+
|
|
130
|
+
__all__ = [
|
|
131
|
+
"__version__",
|
|
132
|
+
# checkpoint
|
|
133
|
+
"Checkpoint",
|
|
134
|
+
"JsonlSink",
|
|
135
|
+
"RunMetrics",
|
|
136
|
+
# errors (единая иерархия ERROR-HUB)
|
|
137
|
+
"CliError",
|
|
138
|
+
"ApiError",
|
|
139
|
+
"AuthRequired",
|
|
140
|
+
"SessionExpired",
|
|
141
|
+
"RateLimited",
|
|
142
|
+
"ValidationError",
|
|
143
|
+
"NotImplementedYet",
|
|
144
|
+
"NotFoundError",
|
|
145
|
+
"ServerError",
|
|
146
|
+
"TransportError",
|
|
147
|
+
"Blocked",
|
|
148
|
+
"RETRYABLE",
|
|
149
|
+
"AdapterError",
|
|
150
|
+
"NotFound",
|
|
151
|
+
# config_util / paths
|
|
152
|
+
"deep_merge",
|
|
153
|
+
"interpolate_env",
|
|
154
|
+
"load_dotenv",
|
|
155
|
+
"slugify",
|
|
156
|
+
"normalize_account_id",
|
|
157
|
+
"atomic_write_text",
|
|
158
|
+
"chmod_600",
|
|
159
|
+
"AppPaths",
|
|
160
|
+
# contract — generic «талия» (Protocol + enums + DTO координат сессии/кредов)
|
|
161
|
+
"PaginationMode",
|
|
162
|
+
"AuthMode",
|
|
163
|
+
"TransportKind",
|
|
164
|
+
"SessionRef",
|
|
165
|
+
"Creds",
|
|
166
|
+
"RequestBody",
|
|
167
|
+
"ResponseLike",
|
|
168
|
+
"Transport",
|
|
169
|
+
"StreamTransport",
|
|
170
|
+
"Codec",
|
|
171
|
+
"Auth",
|
|
172
|
+
"Refreshable",
|
|
173
|
+
"ErrorMapper",
|
|
174
|
+
"Paginator",
|
|
175
|
+
"SessionStoreProtocol",
|
|
176
|
+
# protocols — онбординг/health контракты (опциональные)
|
|
177
|
+
"LoginMode",
|
|
178
|
+
"LoginRequirements",
|
|
179
|
+
"InteractiveFlow",
|
|
180
|
+
"OnboardingProtocol",
|
|
181
|
+
"HealthState",
|
|
182
|
+
"HealthStatus",
|
|
183
|
+
"HealthProtocol",
|
|
184
|
+
# entities (W6) — нейтральные data-классы оркестраторов (почва под W7)
|
|
185
|
+
"Session",
|
|
186
|
+
"SessionChanges",
|
|
187
|
+
"SessionContext",
|
|
188
|
+
"HealthReport",
|
|
189
|
+
# secret_store — keyring + file-fallback
|
|
190
|
+
"SecretStore",
|
|
191
|
+
# sessions (W4): envelope-шифрованное хранилище сессий (spec §4)
|
|
192
|
+
"SessionStore",
|
|
193
|
+
"SessionStoreError",
|
|
194
|
+
"KekUnavailableError",
|
|
195
|
+
"resolve_kek",
|
|
196
|
+
# transport (W4): конкретный httpx-транспорт + choke-point клиент
|
|
197
|
+
"HttpxTransport",
|
|
198
|
+
"HttpClient",
|
|
199
|
+
# rpc (E1): codec-слой + RPC choke-point поверх HttpClient
|
|
200
|
+
"JsonCodec",
|
|
201
|
+
"PrefixedJsonCodec",
|
|
202
|
+
"RpcClient",
|
|
203
|
+
# stream (E1): WS-подобные persistent-транспорты (Stub + websockets reference)
|
|
204
|
+
"StubStreamTransport",
|
|
205
|
+
"WebSocketsStreamTransport",
|
|
206
|
+
"StreamClosedError",
|
|
207
|
+
# errmap (W4): декларативная карта HTTP-ответ → доменная ошибка
|
|
208
|
+
"ErrorMap",
|
|
209
|
+
"ErrorMapBuilder",
|
|
210
|
+
"BodyRule",
|
|
211
|
+
"ExcFactory",
|
|
212
|
+
"AuthExpired",
|
|
213
|
+
"build_error_map",
|
|
214
|
+
"DEFAULT_ERROR_MAP",
|
|
215
|
+
# pagination (W4): листатель ресурса (offset/cursor/page) tweepy-стиля
|
|
216
|
+
"CursorPaginator",
|
|
217
|
+
"PageParams",
|
|
218
|
+
"DEFAULT_PAGE_PARAMS",
|
|
219
|
+
"ItemsExtractor",
|
|
220
|
+
"CursorExtractor",
|
|
221
|
+
"default_extract_items",
|
|
222
|
+
"default_extract_cursor",
|
|
223
|
+
"with_page_params",
|
|
224
|
+
# auth (W4): стратегии авторизации + персистентность сессии
|
|
225
|
+
"TokenAuth",
|
|
226
|
+
"CookieSessionAuth",
|
|
227
|
+
"OAuth2Auth",
|
|
228
|
+
"BrowserLoginAuth",
|
|
229
|
+
"dump_settings",
|
|
230
|
+
"load_settings",
|
|
231
|
+
"encrypt_settings",
|
|
232
|
+
"decrypt_settings",
|
|
233
|
+
# retry
|
|
234
|
+
"RetryPolicy",
|
|
235
|
+
"DEFAULT_RETRY",
|
|
236
|
+
"SimpleRetryPolicy",
|
|
237
|
+
"DEFAULT_SIMPLE_RETRY",
|
|
238
|
+
]
|