unrealon 1.0.9__py3-none-any.whl → 1.1.1__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.
Files changed (302) hide show
  1. unrealon/__init__.py +23 -21
  2. unrealon-1.1.1.dist-info/METADATA +722 -0
  3. unrealon-1.1.1.dist-info/RECORD +82 -0
  4. {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info}/WHEEL +1 -1
  5. unrealon-1.1.1.dist-info/entry_points.txt +9 -0
  6. {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info/licenses}/LICENSE +1 -1
  7. unrealon_bridge/__init__.py +114 -0
  8. unrealon_bridge/cli.py +316 -0
  9. unrealon_bridge/client/__init__.py +93 -0
  10. unrealon_bridge/client/base.py +78 -0
  11. unrealon_bridge/client/commands.py +89 -0
  12. unrealon_bridge/client/connection.py +90 -0
  13. unrealon_bridge/client/events.py +65 -0
  14. unrealon_bridge/client/health.py +38 -0
  15. unrealon_bridge/client/html_parser.py +146 -0
  16. unrealon_bridge/client/logging.py +139 -0
  17. unrealon_bridge/client/proxy.py +70 -0
  18. unrealon_bridge/client/scheduler.py +450 -0
  19. unrealon_bridge/client/session.py +70 -0
  20. unrealon_bridge/configs/__init__.py +14 -0
  21. unrealon_bridge/configs/bridge_config.py +212 -0
  22. unrealon_bridge/configs/bridge_config.yaml +39 -0
  23. unrealon_bridge/models/__init__.py +138 -0
  24. unrealon_bridge/models/base.py +28 -0
  25. unrealon_bridge/models/command.py +41 -0
  26. unrealon_bridge/models/events.py +40 -0
  27. unrealon_bridge/models/html_parser.py +79 -0
  28. unrealon_bridge/models/logging.py +55 -0
  29. unrealon_bridge/models/parser.py +63 -0
  30. unrealon_bridge/models/proxy.py +41 -0
  31. unrealon_bridge/models/requests.py +95 -0
  32. unrealon_bridge/models/responses.py +88 -0
  33. unrealon_bridge/models/scheduler.py +592 -0
  34. unrealon_bridge/models/session.py +28 -0
  35. unrealon_bridge/server/__init__.py +91 -0
  36. unrealon_bridge/server/base.py +171 -0
  37. unrealon_bridge/server/handlers/__init__.py +23 -0
  38. unrealon_bridge/server/handlers/command.py +110 -0
  39. unrealon_bridge/server/handlers/html_parser.py +139 -0
  40. unrealon_bridge/server/handlers/logging.py +95 -0
  41. unrealon_bridge/server/handlers/parser.py +95 -0
  42. unrealon_bridge/server/handlers/proxy.py +75 -0
  43. unrealon_bridge/server/handlers/scheduler.py +545 -0
  44. unrealon_bridge/server/handlers/session.py +66 -0
  45. unrealon_browser/__init__.py +61 -18
  46. unrealon_browser/{src/cli → cli}/browser_cli.py +6 -13
  47. unrealon_browser/{src/cli → cli}/cookies_cli.py +5 -1
  48. unrealon_browser/{src/core → core}/browser_manager.py +2 -2
  49. unrealon_browser/{src/managers → managers}/captcha.py +1 -1
  50. unrealon_browser/{src/managers → managers}/cookies.py +1 -1
  51. unrealon_browser/managers/logger_bridge.py +231 -0
  52. unrealon_browser/{src/managers → managers}/profile.py +1 -1
  53. unrealon_driver/__init__.py +73 -19
  54. unrealon_driver/browser/__init__.py +8 -0
  55. unrealon_driver/browser/config.py +74 -0
  56. unrealon_driver/browser/manager.py +416 -0
  57. unrealon_driver/exceptions.py +28 -0
  58. unrealon_driver/parser/__init__.py +55 -0
  59. unrealon_driver/parser/cli_manager.py +141 -0
  60. unrealon_driver/parser/daemon_manager.py +227 -0
  61. unrealon_driver/parser/managers/__init__.py +46 -0
  62. unrealon_driver/parser/managers/browser.py +51 -0
  63. unrealon_driver/parser/managers/config.py +281 -0
  64. unrealon_driver/parser/managers/error.py +412 -0
  65. unrealon_driver/parser/managers/html.py +732 -0
  66. unrealon_driver/parser/managers/logging.py +609 -0
  67. unrealon_driver/parser/managers/result.py +321 -0
  68. unrealon_driver/parser/parser_manager.py +628 -0
  69. unrealon/sdk_config.py +0 -88
  70. unrealon-1.0.9.dist-info/METADATA +0 -810
  71. unrealon-1.0.9.dist-info/RECORD +0 -246
  72. unrealon_browser/pyproject.toml +0 -182
  73. unrealon_browser/src/__init__.py +0 -62
  74. unrealon_browser/src/managers/logger_bridge.py +0 -395
  75. unrealon_driver/README.md +0 -204
  76. unrealon_driver/pyproject.toml +0 -187
  77. unrealon_driver/src/__init__.py +0 -90
  78. unrealon_driver/src/cli/__init__.py +0 -10
  79. unrealon_driver/src/cli/main.py +0 -66
  80. unrealon_driver/src/cli/simple.py +0 -510
  81. unrealon_driver/src/config/__init__.py +0 -11
  82. unrealon_driver/src/config/auto_config.py +0 -478
  83. unrealon_driver/src/core/__init__.py +0 -18
  84. unrealon_driver/src/core/exceptions.py +0 -289
  85. unrealon_driver/src/core/parser.py +0 -638
  86. unrealon_driver/src/dto/__init__.py +0 -66
  87. unrealon_driver/src/dto/cli.py +0 -119
  88. unrealon_driver/src/dto/config.py +0 -18
  89. unrealon_driver/src/dto/events.py +0 -237
  90. unrealon_driver/src/dto/execution.py +0 -313
  91. unrealon_driver/src/dto/services.py +0 -311
  92. unrealon_driver/src/execution/__init__.py +0 -23
  93. unrealon_driver/src/execution/daemon_mode.py +0 -317
  94. unrealon_driver/src/execution/interactive_mode.py +0 -88
  95. unrealon_driver/src/execution/modes.py +0 -45
  96. unrealon_driver/src/execution/scheduled_mode.py +0 -209
  97. unrealon_driver/src/execution/test_mode.py +0 -250
  98. unrealon_driver/src/logging/__init__.py +0 -24
  99. unrealon_driver/src/logging/driver_logger.py +0 -512
  100. unrealon_driver/src/services/__init__.py +0 -24
  101. unrealon_driver/src/services/browser_service.py +0 -726
  102. unrealon_driver/src/services/llm/__init__.py +0 -15
  103. unrealon_driver/src/services/llm/browser_llm_service.py +0 -363
  104. unrealon_driver/src/services/llm/llm.py +0 -195
  105. unrealon_driver/src/services/logger_service.py +0 -232
  106. unrealon_driver/src/services/metrics_service.py +0 -185
  107. unrealon_driver/src/services/scheduler_service.py +0 -489
  108. unrealon_driver/src/services/websocket_service.py +0 -362
  109. unrealon_driver/src/utils/__init__.py +0 -16
  110. unrealon_driver/src/utils/service_factory.py +0 -317
  111. unrealon_driver/src/utils/time_formatter.py +0 -338
  112. unrealon_llm/README.md +0 -44
  113. unrealon_llm/__init__.py +0 -26
  114. unrealon_llm/pyproject.toml +0 -154
  115. unrealon_llm/src/__init__.py +0 -228
  116. unrealon_llm/src/cli/__init__.py +0 -0
  117. unrealon_llm/src/core/__init__.py +0 -11
  118. unrealon_llm/src/core/smart_client.py +0 -438
  119. unrealon_llm/src/dto/__init__.py +0 -155
  120. unrealon_llm/src/dto/models/__init__.py +0 -0
  121. unrealon_llm/src/dto/models/config.py +0 -343
  122. unrealon_llm/src/dto/models/core.py +0 -328
  123. unrealon_llm/src/dto/models/enums.py +0 -123
  124. unrealon_llm/src/dto/models/html_analysis.py +0 -345
  125. unrealon_llm/src/dto/models/statistics.py +0 -473
  126. unrealon_llm/src/dto/models/translation.py +0 -383
  127. unrealon_llm/src/dto/models/type_conversion.py +0 -462
  128. unrealon_llm/src/dto/schemas/__init__.py +0 -0
  129. unrealon_llm/src/exceptions.py +0 -392
  130. unrealon_llm/src/llm_config/__init__.py +0 -20
  131. unrealon_llm/src/llm_config/logging_config.py +0 -178
  132. unrealon_llm/src/llm_logging/__init__.py +0 -42
  133. unrealon_llm/src/llm_logging/llm_events.py +0 -107
  134. unrealon_llm/src/llm_logging/llm_logger.py +0 -466
  135. unrealon_llm/src/managers/__init__.py +0 -15
  136. unrealon_llm/src/managers/cache_manager.py +0 -67
  137. unrealon_llm/src/managers/cost_manager.py +0 -107
  138. unrealon_llm/src/managers/request_manager.py +0 -298
  139. unrealon_llm/src/modules/__init__.py +0 -0
  140. unrealon_llm/src/modules/html_processor/__init__.py +0 -25
  141. unrealon_llm/src/modules/html_processor/base_processor.py +0 -415
  142. unrealon_llm/src/modules/html_processor/details_processor.py +0 -85
  143. unrealon_llm/src/modules/html_processor/listing_processor.py +0 -91
  144. unrealon_llm/src/modules/html_processor/models/__init__.py +0 -20
  145. unrealon_llm/src/modules/html_processor/models/processing_models.py +0 -40
  146. unrealon_llm/src/modules/html_processor/models/universal_model.py +0 -56
  147. unrealon_llm/src/modules/html_processor/processor.py +0 -102
  148. unrealon_llm/src/modules/llm/__init__.py +0 -0
  149. unrealon_llm/src/modules/translator/__init__.py +0 -0
  150. unrealon_llm/src/provider.py +0 -116
  151. unrealon_llm/src/utils/__init__.py +0 -95
  152. unrealon_llm/src/utils/common.py +0 -64
  153. unrealon_llm/src/utils/data_extractor.py +0 -188
  154. unrealon_llm/src/utils/html_cleaner.py +0 -767
  155. unrealon_llm/src/utils/language_detector.py +0 -308
  156. unrealon_llm/src/utils/models_cache.py +0 -592
  157. unrealon_llm/src/utils/smart_counter.py +0 -229
  158. unrealon_llm/src/utils/token_counter.py +0 -189
  159. unrealon_sdk/README.md +0 -25
  160. unrealon_sdk/__init__.py +0 -30
  161. unrealon_sdk/pyproject.toml +0 -231
  162. unrealon_sdk/src/__init__.py +0 -150
  163. unrealon_sdk/src/cli/__init__.py +0 -12
  164. unrealon_sdk/src/cli/commands/__init__.py +0 -22
  165. unrealon_sdk/src/cli/commands/benchmark.py +0 -42
  166. unrealon_sdk/src/cli/commands/diagnostics.py +0 -573
  167. unrealon_sdk/src/cli/commands/health.py +0 -46
  168. unrealon_sdk/src/cli/commands/integration.py +0 -498
  169. unrealon_sdk/src/cli/commands/reports.py +0 -43
  170. unrealon_sdk/src/cli/commands/security.py +0 -36
  171. unrealon_sdk/src/cli/commands/server.py +0 -483
  172. unrealon_sdk/src/cli/commands/servers.py +0 -56
  173. unrealon_sdk/src/cli/commands/tests.py +0 -55
  174. unrealon_sdk/src/cli/main.py +0 -126
  175. unrealon_sdk/src/cli/utils/reporter.py +0 -519
  176. unrealon_sdk/src/clients/openapi.yaml +0 -3347
  177. unrealon_sdk/src/clients/python_http/__init__.py +0 -3
  178. unrealon_sdk/src/clients/python_http/api_config.py +0 -228
  179. unrealon_sdk/src/clients/python_http/models/BaseModel.py +0 -12
  180. unrealon_sdk/src/clients/python_http/models/BroadcastDeliveryStats.py +0 -33
  181. unrealon_sdk/src/clients/python_http/models/BroadcastMessage.py +0 -17
  182. unrealon_sdk/src/clients/python_http/models/BroadcastMessageRequest.py +0 -35
  183. unrealon_sdk/src/clients/python_http/models/BroadcastPriority.py +0 -10
  184. unrealon_sdk/src/clients/python_http/models/BroadcastResponse.py +0 -21
  185. unrealon_sdk/src/clients/python_http/models/BroadcastResultResponse.py +0 -33
  186. unrealon_sdk/src/clients/python_http/models/BroadcastTarget.py +0 -11
  187. unrealon_sdk/src/clients/python_http/models/ConnectionStats.py +0 -27
  188. unrealon_sdk/src/clients/python_http/models/ConnectionsResponse.py +0 -21
  189. unrealon_sdk/src/clients/python_http/models/DeveloperMessageResponse.py +0 -23
  190. unrealon_sdk/src/clients/python_http/models/ErrorResponse.py +0 -25
  191. unrealon_sdk/src/clients/python_http/models/HTTPValidationError.py +0 -16
  192. unrealon_sdk/src/clients/python_http/models/HealthResponse.py +0 -23
  193. unrealon_sdk/src/clients/python_http/models/HealthStatus.py +0 -33
  194. unrealon_sdk/src/clients/python_http/models/LogLevel.py +0 -10
  195. unrealon_sdk/src/clients/python_http/models/LoggingRequest.py +0 -27
  196. unrealon_sdk/src/clients/python_http/models/LoggingResponse.py +0 -23
  197. unrealon_sdk/src/clients/python_http/models/MaintenanceMode.py +0 -9
  198. unrealon_sdk/src/clients/python_http/models/MaintenanceModeRequest.py +0 -33
  199. unrealon_sdk/src/clients/python_http/models/MaintenanceStatusResponse.py +0 -39
  200. unrealon_sdk/src/clients/python_http/models/ParserCommandRequest.py +0 -25
  201. unrealon_sdk/src/clients/python_http/models/ParserMessageResponse.py +0 -21
  202. unrealon_sdk/src/clients/python_http/models/ParserRegistrationRequest.py +0 -28
  203. unrealon_sdk/src/clients/python_http/models/ParserRegistrationResponse.py +0 -25
  204. unrealon_sdk/src/clients/python_http/models/ParserType.py +0 -10
  205. unrealon_sdk/src/clients/python_http/models/ProxyBlockRequest.py +0 -19
  206. unrealon_sdk/src/clients/python_http/models/ProxyEndpointResponse.py +0 -20
  207. unrealon_sdk/src/clients/python_http/models/ProxyListResponse.py +0 -19
  208. unrealon_sdk/src/clients/python_http/models/ProxyProvider.py +0 -10
  209. unrealon_sdk/src/clients/python_http/models/ProxyPurchaseRequest.py +0 -25
  210. unrealon_sdk/src/clients/python_http/models/ProxyResponse.py +0 -47
  211. unrealon_sdk/src/clients/python_http/models/ProxyRotationRequest.py +0 -23
  212. unrealon_sdk/src/clients/python_http/models/ProxyStatus.py +0 -10
  213. unrealon_sdk/src/clients/python_http/models/ProxyUsageRequest.py +0 -19
  214. unrealon_sdk/src/clients/python_http/models/ProxyUsageStatsResponse.py +0 -26
  215. unrealon_sdk/src/clients/python_http/models/ServiceRegistrationDto.py +0 -23
  216. unrealon_sdk/src/clients/python_http/models/ServiceStatsResponse.py +0 -31
  217. unrealon_sdk/src/clients/python_http/models/SessionStartRequest.py +0 -23
  218. unrealon_sdk/src/clients/python_http/models/SuccessResponse.py +0 -25
  219. unrealon_sdk/src/clients/python_http/models/SystemNotificationResponse.py +0 -23
  220. unrealon_sdk/src/clients/python_http/models/ValidationError.py +0 -18
  221. unrealon_sdk/src/clients/python_http/models/ValidationErrorResponse.py +0 -21
  222. unrealon_sdk/src/clients/python_http/models/WebSocketMetrics.py +0 -21
  223. unrealon_sdk/src/clients/python_http/models/__init__.py +0 -44
  224. unrealon_sdk/src/clients/python_http/services/None_service.py +0 -35
  225. unrealon_sdk/src/clients/python_http/services/ParserManagement_service.py +0 -190
  226. unrealon_sdk/src/clients/python_http/services/ProxyManagement_service.py +0 -289
  227. unrealon_sdk/src/clients/python_http/services/SocketLogging_service.py +0 -187
  228. unrealon_sdk/src/clients/python_http/services/SystemHealth_service.py +0 -119
  229. unrealon_sdk/src/clients/python_http/services/WebSocketAPI_service.py +0 -198
  230. unrealon_sdk/src/clients/python_http/services/__init__.py +0 -0
  231. unrealon_sdk/src/clients/python_http/services/admin_service.py +0 -125
  232. unrealon_sdk/src/clients/python_http/services/async_None_service.py +0 -35
  233. unrealon_sdk/src/clients/python_http/services/async_ParserManagement_service.py +0 -190
  234. unrealon_sdk/src/clients/python_http/services/async_ProxyManagement_service.py +0 -289
  235. unrealon_sdk/src/clients/python_http/services/async_SocketLogging_service.py +0 -189
  236. unrealon_sdk/src/clients/python_http/services/async_SystemHealth_service.py +0 -123
  237. unrealon_sdk/src/clients/python_http/services/async_WebSocketAPI_service.py +0 -200
  238. unrealon_sdk/src/clients/python_http/services/async_admin_service.py +0 -125
  239. unrealon_sdk/src/clients/python_websocket/__init__.py +0 -28
  240. unrealon_sdk/src/clients/python_websocket/client.py +0 -490
  241. unrealon_sdk/src/clients/python_websocket/events.py +0 -732
  242. unrealon_sdk/src/clients/python_websocket/example.py +0 -136
  243. unrealon_sdk/src/clients/python_websocket/types.py +0 -871
  244. unrealon_sdk/src/core/__init__.py +0 -64
  245. unrealon_sdk/src/core/client.py +0 -556
  246. unrealon_sdk/src/core/config.py +0 -465
  247. unrealon_sdk/src/core/exceptions.py +0 -239
  248. unrealon_sdk/src/core/metadata.py +0 -191
  249. unrealon_sdk/src/core/models.py +0 -142
  250. unrealon_sdk/src/core/types.py +0 -68
  251. unrealon_sdk/src/dto/__init__.py +0 -268
  252. unrealon_sdk/src/dto/authentication.py +0 -108
  253. unrealon_sdk/src/dto/cache.py +0 -208
  254. unrealon_sdk/src/dto/common.py +0 -19
  255. unrealon_sdk/src/dto/concurrency.py +0 -393
  256. unrealon_sdk/src/dto/events.py +0 -108
  257. unrealon_sdk/src/dto/health.py +0 -339
  258. unrealon_sdk/src/dto/load_balancing.py +0 -336
  259. unrealon_sdk/src/dto/logging.py +0 -230
  260. unrealon_sdk/src/dto/performance.py +0 -165
  261. unrealon_sdk/src/dto/rate_limiting.py +0 -295
  262. unrealon_sdk/src/dto/resource_pooling.py +0 -128
  263. unrealon_sdk/src/dto/structured_logging.py +0 -112
  264. unrealon_sdk/src/dto/task_scheduling.py +0 -121
  265. unrealon_sdk/src/dto/websocket.py +0 -55
  266. unrealon_sdk/src/enterprise/__init__.py +0 -59
  267. unrealon_sdk/src/enterprise/authentication.py +0 -401
  268. unrealon_sdk/src/enterprise/cache_manager.py +0 -578
  269. unrealon_sdk/src/enterprise/error_recovery.py +0 -494
  270. unrealon_sdk/src/enterprise/event_system.py +0 -549
  271. unrealon_sdk/src/enterprise/health_monitor.py +0 -747
  272. unrealon_sdk/src/enterprise/load_balancer.py +0 -964
  273. unrealon_sdk/src/enterprise/logging/__init__.py +0 -68
  274. unrealon_sdk/src/enterprise/logging/cleanup.py +0 -156
  275. unrealon_sdk/src/enterprise/logging/development.py +0 -744
  276. unrealon_sdk/src/enterprise/logging/service.py +0 -410
  277. unrealon_sdk/src/enterprise/multithreading_manager.py +0 -853
  278. unrealon_sdk/src/enterprise/performance_monitor.py +0 -539
  279. unrealon_sdk/src/enterprise/proxy_manager.py +0 -696
  280. unrealon_sdk/src/enterprise/rate_limiter.py +0 -652
  281. unrealon_sdk/src/enterprise/resource_pool.py +0 -763
  282. unrealon_sdk/src/enterprise/task_scheduler.py +0 -709
  283. unrealon_sdk/src/internal/__init__.py +0 -10
  284. unrealon_sdk/src/internal/command_router.py +0 -497
  285. unrealon_sdk/src/internal/connection_manager.py +0 -397
  286. unrealon_sdk/src/internal/http_client.py +0 -446
  287. unrealon_sdk/src/internal/websocket_client.py +0 -420
  288. unrealon_sdk/src/provider.py +0 -471
  289. unrealon_sdk/src/utils.py +0 -234
  290. /unrealon_browser/{src/cli → cli}/__init__.py +0 -0
  291. /unrealon_browser/{src/cli → cli}/interactive_mode.py +0 -0
  292. /unrealon_browser/{src/cli → cli}/main.py +0 -0
  293. /unrealon_browser/{src/core → core}/__init__.py +0 -0
  294. /unrealon_browser/{src/dto → dto}/__init__.py +0 -0
  295. /unrealon_browser/{src/dto → dto}/models/config.py +0 -0
  296. /unrealon_browser/{src/dto → dto}/models/core.py +0 -0
  297. /unrealon_browser/{src/dto → dto}/models/dataclasses.py +0 -0
  298. /unrealon_browser/{src/dto → dto}/models/detection.py +0 -0
  299. /unrealon_browser/{src/dto → dto}/models/enums.py +0 -0
  300. /unrealon_browser/{src/dto → dto}/models/statistics.py +0 -0
  301. /unrealon_browser/{src/managers → managers}/__init__.py +0 -0
  302. /unrealon_browser/{src/managers → managers}/stealth.py +0 -0
@@ -0,0 +1,212 @@
1
+ """
2
+ Bridge Server Configuration
3
+
4
+ Pydantic2-based configuration management for the bridge server.
5
+ Includes default test API keys for debugging.
6
+ """
7
+
8
+ import os
9
+ import yaml
10
+ from pathlib import Path
11
+ from typing import Optional, Dict, List, Any
12
+ from pydantic import BaseModel, Field, ConfigDict, field_validator
13
+
14
+
15
+ class RedisConfig(BaseModel):
16
+ """Redis connection configuration."""
17
+
18
+ model_config = ConfigDict(str_strip_whitespace=True)
19
+
20
+ url: str = Field(default="redis://localhost:6379/0", description="Redis connection URL")
21
+ max_connections: int = Field(default=10, description="Maximum Redis connections")
22
+ connection_timeout: int = Field(default=5, description="Redis connection timeout in seconds")
23
+
24
+
25
+ class WebSocketConfig(BaseModel):
26
+ """WebSocket server configuration."""
27
+
28
+ model_config = ConfigDict(str_strip_whitespace=True)
29
+
30
+ host: str = Field(default="localhost", description="WebSocket server host")
31
+ port: int = Field(default=8002, description="WebSocket server port")
32
+ max_connections: int = Field(default=100, description="Maximum WebSocket connections")
33
+ ping_interval: int = Field(default=20, description="WebSocket ping interval in seconds")
34
+ ping_timeout: int = Field(default=10, description="WebSocket ping timeout in seconds")
35
+
36
+
37
+ class SecurityConfig(BaseModel):
38
+ """Security and authentication configuration."""
39
+
40
+ model_config = ConfigDict(str_strip_whitespace=True)
41
+
42
+ # Default test API keys for debugging
43
+ test_api_keys: List[str] = Field(default=["amazon_parser_key_123", "test_parser_key_456", "debug_key_789", "development_key_000"], description="Test API keys for debugging (DO NOT USE IN PRODUCTION)")
44
+
45
+ # Production API keys (loaded from environment or config)
46
+ api_keys: List[str] = Field(default_factory=list, description="Production API keys")
47
+
48
+ require_api_key: bool = Field(default=True, description="Whether API key is required for parser registration")
49
+
50
+ allow_test_keys: bool = Field(default=True, description="Allow test API keys (disable in production)")
51
+
52
+
53
+ class RPCConfig(BaseModel):
54
+ """RPC configuration."""
55
+
56
+ model_config = ConfigDict(str_strip_whitespace=True)
57
+
58
+ channel: str = Field(default="amazon_parser_rpc", description="RPC channel name")
59
+ timeout: int = Field(default=30, description="RPC call timeout in seconds")
60
+
61
+
62
+ class PubSubConfig(BaseModel):
63
+ """PubSub configuration."""
64
+
65
+ model_config = ConfigDict(str_strip_whitespace=True)
66
+
67
+ prefix: str = Field(default="amazon_parser", description="PubSub channel prefix")
68
+
69
+
70
+ class LoggingConfig(BaseModel):
71
+ """Logging configuration."""
72
+
73
+ model_config = ConfigDict(str_strip_whitespace=True)
74
+
75
+ level: str = Field(default="INFO", description="Logging level")
76
+ format: str = Field(default="%(asctime)s - %(name)s - %(levelname)s - %(message)s", description="Log message format")
77
+ enable_debug: bool = Field(default=False, description="Enable debug logging")
78
+
79
+
80
+ class BridgeConfig(BaseModel):
81
+ """Main bridge server configuration."""
82
+
83
+ model_config = ConfigDict(str_strip_whitespace=True, validate_assignment=True, extra="forbid")
84
+
85
+ # Sub-configurations
86
+ redis: RedisConfig = Field(default_factory=RedisConfig)
87
+ websocket: WebSocketConfig = Field(default_factory=WebSocketConfig)
88
+ security: SecurityConfig = Field(default_factory=SecurityConfig)
89
+ rpc: RPCConfig = Field(default_factory=RPCConfig)
90
+ pubsub: PubSubConfig = Field(default_factory=PubSubConfig)
91
+ logging: LoggingConfig = Field(default_factory=LoggingConfig)
92
+
93
+ # Environment
94
+ environment: str = Field(default="development", description="Environment (development, testing, production)")
95
+
96
+ def get_all_api_keys(self) -> List[str]:
97
+ """Get all valid API keys (test + production)."""
98
+ all_keys = []
99
+
100
+ # Add production keys
101
+ all_keys.extend(self.security.api_keys)
102
+
103
+ # Add test keys if allowed
104
+ if self.security.allow_test_keys:
105
+ all_keys.extend(self.security.test_api_keys)
106
+
107
+ return all_keys
108
+
109
+ def is_valid_api_key(self, api_key: str) -> bool:
110
+ """Check if API key is valid."""
111
+ if not self.security.require_api_key:
112
+ return True
113
+
114
+ return api_key in self.get_all_api_keys()
115
+
116
+ def is_production(self) -> bool:
117
+ """Check if running in production."""
118
+ return self.environment.lower() == "production"
119
+
120
+ def is_development(self) -> bool:
121
+ """Check if running in development."""
122
+ return self.environment.lower() in ("development", "dev")
123
+
124
+ @field_validator("environment")
125
+ @classmethod
126
+ def validate_environment(cls, v):
127
+ """Validate environment value."""
128
+ valid_envs = ["development", "dev", "testing", "test", "production", "prod"]
129
+ if v.lower() not in valid_envs:
130
+ raise ValueError(f"Environment must be one of: {valid_envs}")
131
+ return v.lower()
132
+
133
+
134
+ # Global config cache
135
+ _config_cache: Optional[BridgeConfig] = None
136
+
137
+
138
+ def get_config_path() -> Path:
139
+ """Get configuration file path."""
140
+ # Check environment variable first
141
+ config_path = os.getenv("BRIDGE_CONFIG_PATH")
142
+ if config_path:
143
+ return Path(config_path)
144
+
145
+ # Default path
146
+ return Path(__file__).parent / "bridge_config.yaml"
147
+
148
+
149
+ def load_bridge_config(config_path: Optional[Path] = None) -> BridgeConfig:
150
+ """
151
+ Load bridge configuration from YAML file.
152
+
153
+ Args:
154
+ config_path: Optional path to config file
155
+
156
+ Returns:
157
+ BridgeConfig instance
158
+ """
159
+ global _config_cache
160
+
161
+ if _config_cache is not None:
162
+ return _config_cache
163
+
164
+ if config_path is None:
165
+ config_path = get_config_path()
166
+
167
+ if config_path.exists():
168
+ with open(config_path, "r", encoding="utf-8") as f:
169
+ config_data = yaml.safe_load(f)
170
+ _config_cache = BridgeConfig(**config_data)
171
+ else:
172
+ # Create default config
173
+ _config_cache = BridgeConfig()
174
+ save_bridge_config(_config_cache, config_path)
175
+
176
+ return _config_cache
177
+
178
+
179
+ def save_bridge_config(config: BridgeConfig, config_path: Optional[Path] = None) -> Path:
180
+ """
181
+ Save bridge configuration to YAML file.
182
+
183
+ Args:
184
+ config: BridgeConfig instance
185
+ config_path: Optional path to save config
186
+
187
+ Returns:
188
+ Path where config was saved
189
+ """
190
+ if config_path is None:
191
+ config_path = get_config_path()
192
+
193
+ config_path.parent.mkdir(parents=True, exist_ok=True)
194
+
195
+ with open(config_path, "w", encoding="utf-8") as f:
196
+ yaml.dump(config.model_dump(), f, default_flow_style=False, indent=2, allow_unicode=True)
197
+
198
+ return config_path
199
+
200
+
201
+ def reload_config() -> BridgeConfig:
202
+ """Reload configuration from file, clearing cache."""
203
+ global _config_cache
204
+ _config_cache = None
205
+ return load_bridge_config()
206
+
207
+
208
+ def create_sample_config() -> BridgeConfig:
209
+ """Create a sample configuration for testing."""
210
+ return BridgeConfig(
211
+ environment="development", websocket=WebSocketConfig(host="localhost", port=8002), security=SecurityConfig(test_api_keys=["amazon_parser_key_123", "test_parser_key_456", "debug_key_789"], allow_test_keys=True, require_api_key=True), logging=LoggingConfig(level="DEBUG", enable_debug=True)
212
+ )
@@ -0,0 +1,39 @@
1
+ environment: development
2
+
3
+ redis:
4
+ url: redis://localhost:6379/0
5
+ max_connections: 10
6
+ connection_timeout: 5
7
+
8
+ websocket:
9
+ host: localhost
10
+ port: 8002
11
+ max_connections: 100
12
+ ping_interval: 20
13
+ ping_timeout: 10
14
+
15
+ security:
16
+ # Test API keys for debugging (DO NOT USE IN PRODUCTION)
17
+ test_api_keys:
18
+ - amazon_parser_key_123
19
+ - test_parser_key_456
20
+ - debug_key_789
21
+ - development_key_000
22
+
23
+ # Production API keys (add your keys here)
24
+ api_keys: []
25
+
26
+ require_api_key: true
27
+ allow_test_keys: true
28
+
29
+ rpc:
30
+ channel: amazon_parser_rpc
31
+ timeout: 30
32
+
33
+ pubsub:
34
+ prefix: amazon_parser
35
+
36
+ logging:
37
+ level: INFO
38
+ format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
39
+ enable_debug: false
@@ -0,0 +1,138 @@
1
+ """
2
+ Bridge Parsers Models - Decomposed and strictly typed.
3
+
4
+ All models follow CRITICAL_REQUIREMENTS.md:
5
+ - NO Dict[str, Any] usage
6
+ - Strict Pydantic v2 typing
7
+ - NO raw JSON handling
8
+ - Complete type annotations
9
+ """
10
+
11
+ # Base models
12
+ from .base import BaseParserModel, BaseRPCRequest, BaseRPCResponse
13
+
14
+ # Core domain models
15
+ from .parser import ParserInfo, ParserStats, ParserHealth, ParserSystemStats
16
+ from .command import ParserCommand, CommandResult
17
+ from .proxy import ProxyRequest, ProxyInfo
18
+ from .session import ParserSession
19
+ from .events import ParserEvent, WebhookConfig
20
+ from .html_parser import (
21
+ HTMLParseRequest, HTMLParseResult, HTMLParseResponse,
22
+ HTMLParseRPCRequest, HTMLParseRPCResponse
23
+ )
24
+ from .logging import (
25
+ ParserLogEntry, ParserLogRequest, ParserLogResponse
26
+ )
27
+ from .scheduler import (
28
+ TaskStatus, TaskPriority, ScheduleType, TaskExecutionMode,
29
+ CronExpression, TaskParameters, TaskRetryConfig, ScheduledTask,
30
+ TaskQueue, TaskExecutionResult, ParserStatus,
31
+ SchedulerError, TaskValidationError, TaskExecutionError,
32
+ ParserUnavailableError, QueueError
33
+ )
34
+
35
+ # RPC Request models (strict typing)
36
+ from .requests import (
37
+ ParserRegisterRequest,
38
+ ParserStatusRequest,
39
+ ParserListRequest,
40
+ ParserHealthRequest,
41
+ SessionStartRequest,
42
+ SessionEndRequest,
43
+ CommandExecuteRequest,
44
+ CommandCreateRequest,
45
+ CommandStatusRequest,
46
+ ProxyAllocateRequest,
47
+ ProxyReleaseRequest,
48
+ ProxyCheckRequest,
49
+ )
50
+
51
+ # RPC Response models (strict typing)
52
+ from .responses import (
53
+ ParserRegisterResponse,
54
+ ParserStatusResponse,
55
+ ParserListResponse,
56
+ ParserHealthResponse,
57
+ SessionStartResponse,
58
+ SessionEndResponse,
59
+ CommandExecuteResponse,
60
+ CommandCreateResponse,
61
+ CommandStatusResponse,
62
+ ProxyAllocateResponse,
63
+ ProxyReleaseResponse,
64
+ ProxyCheckResponse,
65
+ )
66
+
67
+ __all__ = [
68
+ # Base models
69
+ "BaseParserModel",
70
+ "BaseRPCRequest",
71
+ "BaseRPCResponse",
72
+ # Core domain models
73
+ "ParserInfo",
74
+ "ParserStats",
75
+ "ParserHealth",
76
+ "ParserSystemStats",
77
+ "ParserCommand",
78
+ "CommandResult",
79
+ "ProxyRequest",
80
+ "ProxyInfo",
81
+ "ParserSession",
82
+ "ParserEvent",
83
+ "WebhookConfig",
84
+ # HTML Parser models
85
+ "HTMLParseRequest",
86
+ "HTMLParseResult",
87
+ "HTMLParseResponse",
88
+ "HTMLParseRPCRequest",
89
+ "HTMLParseRPCResponse",
90
+ # Parser Logging models
91
+ "ParserLogEntry",
92
+ "ParserLogRequest",
93
+ "ParserLogResponse",
94
+ # Scheduler models
95
+ "TaskStatus",
96
+ "TaskPriority",
97
+ "ScheduleType",
98
+ "TaskExecutionMode",
99
+ "CronExpression",
100
+ "TaskParameters",
101
+ "TaskRetryConfig",
102
+ "ScheduledTask",
103
+ "TaskQueue",
104
+ "TaskExecutionResult",
105
+ "ParserStatus",
106
+ # Scheduler exceptions
107
+ "SchedulerError",
108
+ "TaskValidationError",
109
+ "TaskExecutionError",
110
+ "ParserUnavailableError",
111
+ "QueueError",
112
+ # RPC Request models
113
+ "ParserRegisterRequest",
114
+ "ParserStatusRequest",
115
+ "ParserListRequest",
116
+ "ParserHealthRequest",
117
+ "SessionStartRequest",
118
+ "SessionEndRequest",
119
+ "CommandExecuteRequest",
120
+ "CommandCreateRequest",
121
+ "CommandStatusRequest",
122
+ "ProxyAllocateRequest",
123
+ "ProxyReleaseRequest",
124
+ "ProxyCheckRequest",
125
+ # RPC Response models
126
+ "ParserRegisterResponse",
127
+ "ParserStatusResponse",
128
+ "ParserListResponse",
129
+ "ParserHealthResponse",
130
+ "SessionStartResponse",
131
+ "SessionEndResponse",
132
+ "CommandExecuteResponse",
133
+ "CommandCreateResponse",
134
+ "CommandStatusResponse",
135
+ "ProxyAllocateResponse",
136
+ "ProxyReleaseResponse",
137
+ "ProxyCheckResponse",
138
+ ]
@@ -0,0 +1,28 @@
1
+ """
2
+ Base models for parser bridge operations.
3
+
4
+ Provides common base classes and shared types for all parser models.
5
+ """
6
+
7
+ from pydantic import BaseModel, Field, ConfigDict
8
+ from typing import Optional
9
+
10
+
11
+ class BaseParserModel(BaseModel):
12
+ """Base class for all parser models with strict validation."""
13
+
14
+ model_config = ConfigDict(extra="forbid", validate_assignment=True, str_strip_whitespace=True, validate_default=True)
15
+
16
+
17
+ class BaseRPCRequest(BaseParserModel):
18
+ """Base class for all RPC requests."""
19
+
20
+ pass
21
+
22
+
23
+ class BaseRPCResponse(BaseParserModel):
24
+ """Base class for all RPC responses."""
25
+
26
+ success: bool = Field(description="Whether the operation was successful")
27
+ message: Optional[str] = Field(default=None, description="Human-readable message")
28
+ error: Optional[str] = Field(default=None, description="Error message if success=False")
@@ -0,0 +1,41 @@
1
+ """
2
+ Command-related models.
3
+
4
+ Contains models for command execution, tracking, and results.
5
+ """
6
+
7
+ from typing import Optional, Dict, Literal, Any
8
+ from datetime import datetime
9
+ from pydantic import Field
10
+ from typing_extensions import Annotated
11
+
12
+ from .base import BaseParserModel
13
+
14
+
15
+ class ParserCommand(BaseParserModel):
16
+ """Parser command definition and tracking."""
17
+
18
+ command_id: Annotated[str, Field(min_length=1, description="Unique command identifier")]
19
+ command_type: Annotated[str, Field(min_length=1, description="Type of command (scrape, parse, etc.)")]
20
+ parser_id: Annotated[str, Field(min_length=1, description="Parser ID that will execute the command")]
21
+ parameters: Dict[str, str] = Field(default_factory=dict, description="Command parameters")
22
+ status: Literal["pending", "running", "completed", "failed", "cancelled"] = "pending"
23
+ priority: Annotated[int, Field(ge=1, le=10)] = 5
24
+ timeout: Annotated[int, Field(gt=0, le=3600, description="Command timeout in seconds")] = 300
25
+ created_at: datetime = Field(default_factory=datetime.now)
26
+ started_at: Optional[datetime] = None
27
+ completed_at: Optional[datetime] = None
28
+ retry_count: Annotated[int, Field(ge=0)] = 0
29
+ max_retries: Annotated[int, Field(ge=0)] = 3
30
+
31
+
32
+ class CommandResult(BaseParserModel):
33
+ """Result of command execution."""
34
+
35
+ command_id: Annotated[str, Field(min_length=1, description="Command ID")]
36
+ success: bool = Field(description="Whether command executed successfully")
37
+ result_data: Dict[str, Any] = Field(default_factory=dict, description="Command result data")
38
+ error_message: Optional[str] = None
39
+ execution_time: Annotated[float, Field(ge=0)] = 0.0
40
+ output_size: Annotated[int, Field(ge=0)] = 0
41
+ created_at: datetime = Field(default_factory=datetime.now)
@@ -0,0 +1,40 @@
1
+ """
2
+ Event and webhook-related models.
3
+
4
+ Contains models for parser events, logging, and webhook configurations.
5
+ """
6
+
7
+ from typing import Optional, Dict, List, Literal
8
+ from datetime import datetime
9
+ from pydantic import Field
10
+ from typing_extensions import Annotated
11
+
12
+ from .base import BaseParserModel
13
+
14
+
15
+ class ParserEvent(BaseParserModel):
16
+ """Parser event for logging and monitoring."""
17
+
18
+ event_id: Annotated[str, Field(min_length=1, description="Unique event identifier")]
19
+ parser_id: Annotated[str, Field(min_length=1, description="Parser ID")]
20
+ event_type: Annotated[str, Field(min_length=1, description="Type of event")]
21
+ level: Literal["debug", "info", "warning", "error", "critical"] = "info"
22
+ message: Annotated[str, Field(min_length=1, description="Event message")]
23
+ data: Dict[str, str] = Field(default_factory=dict, description="Additional event data (string values only)")
24
+ command_id: Optional[str] = None
25
+ session_id: Optional[str] = None
26
+ timestamp: datetime = Field(default_factory=datetime.now)
27
+ source: Optional[str] = None
28
+
29
+
30
+ class WebhookConfig(BaseParserModel):
31
+ """Webhook configuration for parser events."""
32
+
33
+ webhook_id: Annotated[str, Field(min_length=1, description="Unique webhook identifier")]
34
+ parser_id: Annotated[str, Field(min_length=1, description="Parser ID")]
35
+ url: Annotated[str, Field(min_length=1, description="Webhook URL")]
36
+ events: List[str] = Field(default_factory=list, description="Events to trigger webhook")
37
+ headers: Dict[str, str] = Field(default_factory=dict, description="Custom headers")
38
+ secret: Optional[str] = None
39
+ active: bool = True
40
+ created_at: datetime = Field(default_factory=datetime.now)
@@ -0,0 +1,79 @@
1
+ """
2
+ HTML Parser models for LLM-based HTML parsing.
3
+
4
+ Models for sending HTML content to Django backend for AI-powered parsing.
5
+ """
6
+
7
+ from datetime import datetime
8
+ from typing import Dict, List, Optional, Any
9
+ from pydantic import BaseModel, Field
10
+
11
+ from .base import BaseParserModel
12
+
13
+
14
+ class HTMLParseRequest(BaseParserModel):
15
+ """Request for HTML parsing via AI/LLM."""
16
+
17
+ html_content: str = Field(..., description="Raw HTML content to parse")
18
+ parser_id: str = Field(..., description="ID of the parser making the request")
19
+ url: Optional[str] = Field(None, description="Source URL of the HTML (for context)")
20
+ parse_type: str = Field("general", description="Type of parsing (product, listing, article, etc.)")
21
+ instructions: Optional[str] = Field(None, description="Additional parsing instructions")
22
+ timeout: int = Field(60, description="Timeout in seconds (default 60s for LLM processing)")
23
+ metadata: Dict[str, str] = Field(default_factory=dict, description="Additional metadata")
24
+
25
+
26
+ class HTMLParseResult(BaseParserModel):
27
+ """Result of HTML parsing."""
28
+
29
+ success: bool = Field(..., description="Whether parsing was successful")
30
+ parsed_data: Optional[Dict[str, Any]] = Field(None, description="Parsed JSON data")
31
+ markdown: Optional[str] = Field(None, description="Markdown instructions from Django parser")
32
+ error_message: Optional[str] = Field(None, description="Error message if parsing failed")
33
+
34
+
35
+ class HTMLParseResponse(BaseParserModel):
36
+ """Response for HTML parsing request."""
37
+
38
+ success: bool = Field(..., description="Whether the request was successful")
39
+ message: Optional[str] = Field(None, description="Response message")
40
+ error: Optional[str] = Field(None, description="Error message if failed")
41
+ result: Optional[HTMLParseResult] = Field(None, description="Parsing result")
42
+ request_id: Optional[str] = Field(None, description="Request ID for tracking")
43
+ processed_at: datetime = Field(default_factory=datetime.now, description="When the request was processed")
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+ # Request/Response models for RPC
53
+ class HTMLParseRPCRequest(BaseParserModel):
54
+ """RPC request for HTML parsing."""
55
+
56
+ html_content: str
57
+ parser_id: str
58
+ url: Optional[str] = None
59
+ parse_type: str = "general"
60
+ instructions: Optional[str] = None
61
+ timeout: int = 60
62
+ metadata: Dict[str, str] = Field(default_factory=dict)
63
+
64
+
65
+ class HTMLParseRPCResponse(BaseParserModel):
66
+ """RPC response for HTML parsing."""
67
+
68
+ success: bool
69
+ message: Optional[str] = None
70
+ error: Optional[str] = None
71
+ result: Optional[HTMLParseResult] = None
72
+ request_id: Optional[str] = None
73
+ processed_at: datetime = Field(default_factory=datetime.now)
74
+
75
+
76
+
77
+
78
+
79
+
@@ -0,0 +1,55 @@
1
+ """
2
+ Parser logging models.
3
+
4
+ Models for sending parser logs to Django via WebSocket/Redis.
5
+ """
6
+
7
+ from datetime import datetime
8
+ from typing import Dict, Optional
9
+ from enum import Enum
10
+ from pydantic import BaseModel, Field
11
+
12
+ from .base import BaseParserModel
13
+
14
+
15
+ class ParserLogLevel(str, Enum):
16
+ """Parser log levels."""
17
+
18
+ DEBUG = "DEBUG"
19
+ INFO = "INFO"
20
+ WARNING = "WARNING"
21
+ ERROR = "ERROR"
22
+ CRITICAL = "CRITICAL"
23
+
24
+
25
+ class ParserLogEntry(BaseParserModel):
26
+ """Parser log entry to send to Django."""
27
+
28
+ parser_id: str = Field(..., description="ID of the parser")
29
+ level: str = Field(..., description="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)")
30
+ message: str = Field(..., description="Log message")
31
+ timestamp: datetime = Field(default_factory=datetime.now, description="When the log was created")
32
+
33
+ # Optional context
34
+ session_id: Optional[str] = Field(None, description="Parser session ID")
35
+ command_id: Optional[str] = Field(None, description="Command ID if related to command")
36
+ url: Optional[str] = Field(None, description="URL being processed")
37
+ operation: Optional[str] = Field(None, description="Operation being performed")
38
+
39
+ # Additional data
40
+ data: Dict[str, str] = Field(default_factory=dict, description="Additional log data")
41
+ error_details: Optional[str] = Field(None, description="Error details if error log")
42
+
43
+
44
+ class ParserLogRequest(BaseParserModel):
45
+ """RPC request for sending parser log."""
46
+
47
+ log_entry: ParserLogEntry
48
+
49
+
50
+ class ParserLogResponse(BaseParserModel):
51
+ """RPC response for parser log."""
52
+
53
+ success: bool = Field(..., description="Whether log was sent successfully")
54
+ message: Optional[str] = Field(None, description="Response message")
55
+ error: Optional[str] = Field(None, description="Error message if failed")