pyrestkit 1.2.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.
- pyrestkit/__init__.py +35 -0
- pyrestkit/ai/__init__.py +17 -0
- pyrestkit/ai/analyzer.py +137 -0
- pyrestkit/ai/client.py +101 -0
- pyrestkit/ai/config/__init__.py +5 -0
- pyrestkit/ai/config/ai_config.py +200 -0
- pyrestkit/ai/exceptions.py +22 -0
- pyrestkit/ai/generators/__init__.py +0 -0
- pyrestkit/ai/models.py +44 -0
- pyrestkit/ai/parsers/__init__.py +0 -0
- pyrestkit/ai/prompts/failure_analysis.md +21 -0
- pyrestkit/ai/provider.py +58 -0
- pyrestkit/ai/providers/__init__.py +21 -0
- pyrestkit/ai/providers/anthropic.py +85 -0
- pyrestkit/ai/providers/azure_openai.py +84 -0
- pyrestkit/ai/providers/base.py +39 -0
- pyrestkit/ai/providers/bedrock.py +70 -0
- pyrestkit/ai/providers/cohere.py +82 -0
- pyrestkit/ai/providers/gemini.py +113 -0
- pyrestkit/ai/providers/groq.py +81 -0
- pyrestkit/ai/providers/mistral.py +88 -0
- pyrestkit/ai/providers/ollama.py +82 -0
- pyrestkit/ai/providers/openai.py +124 -0
- pyrestkit/ai/utils/__init__.py +0 -0
- pyrestkit/ai/utils/prompt_loader.py +52 -0
- pyrestkit/assertions/__init__.py +7 -0
- pyrestkit/assertions/assertion_exception.py +4 -0
- pyrestkit/assertions/response_assertions.py +181 -0
- pyrestkit/auth/__init__.py +11 -0
- pyrestkit/auth/auth_strategy.py +14 -0
- pyrestkit/auth/authentication_manager.py +35 -0
- pyrestkit/auth/strategies/__init__.py +5 -0
- pyrestkit/auth/strategies/api_key_auth.py +18 -0
- pyrestkit/auth/strategies/basic_auth.py +24 -0
- pyrestkit/auth/strategies/bearer_auth.py +17 -0
- pyrestkit/auth/token_cache.py +44 -0
- pyrestkit/auth/token_manager.py +32 -0
- pyrestkit/auth/token_provider.py +12 -0
- pyrestkit/auth/token_response.py +13 -0
- pyrestkit/builder/__init__.py +5 -0
- pyrestkit/builder/fluent_request_builder.py +167 -0
- pyrestkit/clients/__init__.py +7 -0
- pyrestkit/clients/base_client.py +68 -0
- pyrestkit/clients/user_client.py +66 -0
- pyrestkit/config/__init__.py +5 -0
- pyrestkit/config/config.py +97 -0
- pyrestkit/constants/__init__.py +0 -0
- pyrestkit/constants/content_types.py +0 -0
- pyrestkit/constants/headers.py +0 -0
- pyrestkit/constants/status_codes.py +0 -0
- pyrestkit/core/__init__.py +13 -0
- pyrestkit/core/api_client.py +129 -0
- pyrestkit/core/logger.py +41 -0
- pyrestkit/core/request_builder.py +45 -0
- pyrestkit/core/request_executor.py +64 -0
- pyrestkit/core/request_logger.py +0 -0
- pyrestkit/core/response_logger.py +0 -0
- pyrestkit/core/session_manager.py +19 -0
- pyrestkit/database/__init__.py +0 -0
- pyrestkit/endpoints/__init__.py +5 -0
- pyrestkit/endpoints/base_endpoints.py +32 -0
- pyrestkit/endpoints/order_endpoints.py +9 -0
- pyrestkit/endpoints/payment_endpoints.py +5 -0
- pyrestkit/endpoints/user_endpoints.py +48 -0
- pyrestkit/exceptions/__init__.py +21 -0
- pyrestkit/exceptions/api_exception.py +8 -0
- pyrestkit/exceptions/authentication_exception.py +10 -0
- pyrestkit/exceptions/configuration_exception.py +10 -0
- pyrestkit/exceptions/exception_mapper.py +32 -0
- pyrestkit/exceptions/network_exception.py +10 -0
- pyrestkit/exceptions/response_exception.py +10 -0
- pyrestkit/exceptions/serialization_exception.py +10 -0
- pyrestkit/exceptions/validation_exception.py +10 -0
- pyrestkit/factories/__init__.py +5 -0
- pyrestkit/factories/base_factory.py +25 -0
- pyrestkit/factories/user_factory.py +37 -0
- pyrestkit/hooks/__init__.py +5 -0
- pyrestkit/hooks/hook.py +27 -0
- pyrestkit/hooks/hook_manager.py +39 -0
- pyrestkit/hooks/request_hook.py +18 -0
- pyrestkit/hooks/response_hook.py +17 -0
- pyrestkit/hooks/timing_hook.py +32 -0
- pyrestkit/models/__init__.py +8 -0
- pyrestkit/models/base_response.py +11 -0
- pyrestkit/models/request/__init__.py +7 -0
- pyrestkit/models/request/create_user_request.py +11 -0
- pyrestkit/models/request/update_user_request.py +10 -0
- pyrestkit/models/response/__init__.py +5 -0
- pyrestkit/models/response/create_user_response.py +26 -0
- pyrestkit/models/response/get_user_response.py +28 -0
- pyrestkit/models/response/user_response.py +12 -0
- pyrestkit/pipeline/__init__.py +5 -0
- pyrestkit/pipeline/middleware.py +18 -0
- pyrestkit/pipeline/middleware_chain.py +11 -0
- pyrestkit/pipeline/pipeline.py +27 -0
- pyrestkit/pipeline/request_context.py +26 -0
- pyrestkit/response/__init__.py +8 -0
- pyrestkit/response/framework_response.py +271 -0
- pyrestkit/response/response_body.py +124 -0
- pyrestkit/retry/__init__.py +5 -0
- pyrestkit/retry/backoff.py +32 -0
- pyrestkit/retry/retry_handler.py +52 -0
- pyrestkit/retry/retry_policy.py +33 -0
- pyrestkit/serializers/__init__.py +0 -0
- pyrestkit/serializers/response_mapper.py +25 -0
- pyrestkit/types/__init__.py +0 -0
- pyrestkit/types/model_protocol.py +17 -0
- pyrestkit/utils/__init__.py +0 -0
- pyrestkit/validators/__init__.py +7 -0
- pyrestkit/validators/response_validator.py +57 -0
- pyrestkit/validators/schema_validator.py +33 -0
- pyrestkit-1.2.0.dist-info/METADATA +741 -0
- pyrestkit-1.2.0.dist-info/RECORD +115 -0
- pyrestkit-1.2.0.dist-info/WHEEL +5 -0
- pyrestkit-1.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyrestkit
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Modern Python REST API Automation Toolkit With AI
|
|
5
|
+
Author: Raushan Raj
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Raushanraj77/pyrestkit
|
|
8
|
+
Project-URL: Repository, https://github.com/Raushanraj77/pyrestkit
|
|
9
|
+
Project-URL: Issues, https://github.com/Raushanraj77/pyrestkit/issues
|
|
10
|
+
Keywords: api,rest,automation,testing,pytest,framework,qa,sdet,ai,llm
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: requests>=2.32.0
|
|
24
|
+
Requires-Dist: pydantic>=2.10.0
|
|
25
|
+
Requires-Dist: jsonschema>=4.23.0
|
|
26
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
27
|
+
Requires-Dist: PyYAML>=6.0
|
|
28
|
+
Provides-Extra: ai
|
|
29
|
+
Requires-Dist: openai>=1.0.0; extra == "ai"
|
|
30
|
+
Requires-Dist: anthropic>=0.30.0; extra == "ai"
|
|
31
|
+
Requires-Dist: boto3>=1.34.0; extra == "ai"
|
|
32
|
+
Requires-Dist: google-generativeai>=0.7.0; extra == "ai"
|
|
33
|
+
Requires-Dist: mistralai>=1.0.0; extra == "ai"
|
|
34
|
+
Requires-Dist: cohere>=5.0.0; extra == "ai"
|
|
35
|
+
Provides-Extra: all
|
|
36
|
+
Requires-Dist: pyrestkit[ai]; extra == "all"
|
|
37
|
+
|
|
38
|
+
# 🚀 PyRestKit
|
|
39
|
+
|
|
40
|
+
> A modern Python framework for REST API automation with built-in validation,
|
|
41
|
+
> authentication, configuration management, and optional AI-assisted failure analysis.
|
|
42
|
+
|
|
43
|
+
[](https://python.org)
|
|
44
|
+
[](https://pypi.org/project/pyrestkit/)
|
|
45
|
+
[](LICENSE)
|
|
46
|
+
[](https://github.com/Raushanraj77/pyrestkit/actions)
|
|
47
|
+
[](https://docs.astral.sh/ruff/)
|
|
48
|
+
[](https://mypy-lang.org/)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Why PyRestKit?
|
|
53
|
+
|
|
54
|
+
Testing REST APIs often requires combining multiple libraries for:
|
|
55
|
+
|
|
56
|
+
- HTTP requests
|
|
57
|
+
- Authentication
|
|
58
|
+
- Configuration management
|
|
59
|
+
- Assertions
|
|
60
|
+
- JSON validation
|
|
61
|
+
- Logging
|
|
62
|
+
- Retry handling
|
|
63
|
+
- Environment management
|
|
64
|
+
|
|
65
|
+
As projects grow, these utilities become difficult to maintain consistently across teams.
|
|
66
|
+
|
|
67
|
+
PyRestKit provides a unified, extensible framework that brings these capabilities together while keeping your test code clean, maintainable, and type-safe.
|
|
68
|
+
|
|
69
|
+
In addition, PyRestKit offers **optional AI-assisted failure analysis**, enabling engineers to receive intelligent explanations and debugging suggestions from multiple Large Language Model (LLM) providers.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
# Features
|
|
74
|
+
|
|
75
|
+
## REST API Client
|
|
76
|
+
|
|
77
|
+
- Simple request API
|
|
78
|
+
- GET / POST / PUT / PATCH / DELETE
|
|
79
|
+
- Custom headers
|
|
80
|
+
- Query parameters
|
|
81
|
+
- Cookies
|
|
82
|
+
- Multipart requests
|
|
83
|
+
- Request timeout support
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Authentication
|
|
88
|
+
|
|
89
|
+
Built-in authentication helpers:
|
|
90
|
+
|
|
91
|
+
- Basic Authentication
|
|
92
|
+
- Bearer Token
|
|
93
|
+
- API Key
|
|
94
|
+
- OAuth 2.0 (yet to implement)
|
|
95
|
+
- Custom authentication strategies
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Validation
|
|
100
|
+
|
|
101
|
+
Powerful response validation utilities.
|
|
102
|
+
|
|
103
|
+
Supported validations include:
|
|
104
|
+
|
|
105
|
+
- Status Code
|
|
106
|
+
- Headers
|
|
107
|
+
- JSON Schema
|
|
108
|
+
- Response Time
|
|
109
|
+
- JSON Path
|
|
110
|
+
- Custom Validators
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
Configuration can be loaded from
|
|
117
|
+
|
|
118
|
+
- YAML
|
|
119
|
+
- Environment Variables
|
|
120
|
+
- Python Objects
|
|
121
|
+
|
|
122
|
+
Supports multiple environments including
|
|
123
|
+
|
|
124
|
+
- Development
|
|
125
|
+
- QA
|
|
126
|
+
- Staging
|
|
127
|
+
- Production
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Assertions
|
|
132
|
+
|
|
133
|
+
Readable assertions for
|
|
134
|
+
|
|
135
|
+
- Status codes
|
|
136
|
+
- Headers
|
|
137
|
+
- JSON values
|
|
138
|
+
- Collections
|
|
139
|
+
- Response time
|
|
140
|
+
- Custom assertions
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## AI-Assisted Failure Analysis
|
|
145
|
+
|
|
146
|
+
PyRestKit can analyze failed API responses using AI.
|
|
147
|
+
|
|
148
|
+
Features include
|
|
149
|
+
|
|
150
|
+
- Root cause explanation
|
|
151
|
+
- Human-readable summaries
|
|
152
|
+
- Suggested fixes
|
|
153
|
+
- Optional system prompts
|
|
154
|
+
- Prompt templates
|
|
155
|
+
- Provider abstraction
|
|
156
|
+
|
|
157
|
+
AI support is completely optional and does not affect users who prefer traditional API testing.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Multiple AI Providers
|
|
162
|
+
|
|
163
|
+
PyRestKit currently supports:
|
|
164
|
+
|
|
165
|
+
| Provider | Supported |
|
|
166
|
+
|-----------|-----------|
|
|
167
|
+
| OpenAI | ✅ |
|
|
168
|
+
| Anthropic | ✅ |
|
|
169
|
+
| Google Gemini | ✅ |
|
|
170
|
+
| Azure OpenAI | ✅ |
|
|
171
|
+
| Groq | ✅ |
|
|
172
|
+
| Cohere | ✅ |
|
|
173
|
+
| Mistral | ✅ |
|
|
174
|
+
| Ollama | ✅ |
|
|
175
|
+
| AWS Bedrock | ✅ |
|
|
176
|
+
|
|
177
|
+
The provider abstraction allows additional providers to be implemented with minimal effort.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
# Installation
|
|
182
|
+
|
|
183
|
+
## Standard Installation
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pip install pyrestkit
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Development Installation
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
git clone https://github.com/Raushanraj77/pyrestkit.git
|
|
195
|
+
|
|
196
|
+
cd pyrestkit
|
|
197
|
+
|
|
198
|
+
python -m venv .venv
|
|
199
|
+
|
|
200
|
+
source .venv/bin/activate
|
|
201
|
+
|
|
202
|
+
pip install -e .
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Verify Installation
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
import pyrestkit
|
|
211
|
+
|
|
212
|
+
print(pyrestkit.__version__)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
# Quick Start
|
|
218
|
+
|
|
219
|
+
## Create a Client
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from pyrestkit import APIClient
|
|
223
|
+
|
|
224
|
+
client = APIClient(base_url="https://jsonplaceholder.typicode.com")
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Send a Request
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
response = client.get("/posts/1")
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Validate Response
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
response.validate_status_code(200)
|
|
241
|
+
|
|
242
|
+
response.validate_json()
|
|
243
|
+
|
|
244
|
+
response.validate_response_time(max_time_ms=1000)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Read JSON
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
data = response.json()
|
|
253
|
+
|
|
254
|
+
print(data["title"])
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
# Authentication Example
|
|
260
|
+
|
|
261
|
+
## Bearer Token
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
client = APIClient(base_url="https://example.com")
|
|
265
|
+
|
|
266
|
+
client.authenticate_bearer(token="your-token")
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Basic Authentication
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
client.authenticate_basic(username="admin", password="secret")
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## API Key
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
client.authenticate_api_key(key="xxxxxxxx", header_name="X-API-Key")
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
# Configuration Example
|
|
288
|
+
|
|
289
|
+
Load configuration from YAML.
|
|
290
|
+
|
|
291
|
+
```yaml
|
|
292
|
+
base_url: https://api.example.com
|
|
293
|
+
|
|
294
|
+
timeout: 30
|
|
295
|
+
|
|
296
|
+
headers:
|
|
297
|
+
Accept: application/json
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
from pyrestkit.config import Config
|
|
302
|
+
|
|
303
|
+
config = Config.from_yaml("config.yaml")
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
# Response Validation
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
response.validate_status_code(200)
|
|
312
|
+
|
|
313
|
+
response.validate_header("Content-Type", "application/json")
|
|
314
|
+
|
|
315
|
+
response.validate_schema("schemas/user.json")
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
# AI Failure Analysis
|
|
321
|
+
|
|
322
|
+
AI analysis can be enabled whenever deeper insight into a failed response is useful.
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
from pyrestkit.ai import AIAnalyzer
|
|
326
|
+
from pyrestkit.ai import AIConfig
|
|
327
|
+
|
|
328
|
+
config = AIConfig(provider="openai", model="gpt-4.1-mini", api_key="YOUR_API_KEY")
|
|
329
|
+
|
|
330
|
+
analyzer = AIAnalyzer(config)
|
|
331
|
+
|
|
332
|
+
analysis = analyzer.analyze(
|
|
333
|
+
request=request,
|
|
334
|
+
response=response,
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
print(analysis)
|
|
338
|
+
```
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
# Supported AI Providers
|
|
342
|
+
|
|
343
|
+
PyRestKit uses a provider abstraction layer that allows switching AI providers
|
|
344
|
+
without changing your test code.
|
|
345
|
+
|
|
346
|
+
```text
|
|
347
|
+
AI Analyzer
|
|
348
|
+
│
|
|
349
|
+
▼
|
|
350
|
+
Provider Factory
|
|
351
|
+
│
|
|
352
|
+
┌────────────────┼────────────────┐
|
|
353
|
+
▼ ▼ ▼
|
|
354
|
+
OpenAI Anthropic Gemini
|
|
355
|
+
│ │ │
|
|
356
|
+
▼ ▼ ▼
|
|
357
|
+
Groq Cohere Azure OpenAI
|
|
358
|
+
│
|
|
359
|
+
▼
|
|
360
|
+
Mistral
|
|
361
|
+
│
|
|
362
|
+
▼
|
|
363
|
+
Ollama
|
|
364
|
+
│
|
|
365
|
+
▼
|
|
366
|
+
AWS Bedrock
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Every provider implements the same interface.
|
|
370
|
+
|
|
371
|
+
```python
|
|
372
|
+
class BaseAIProvider:
|
|
373
|
+
def complete(
|
|
374
|
+
self,
|
|
375
|
+
prompt: str,
|
|
376
|
+
*,
|
|
377
|
+
config: AIConfig,
|
|
378
|
+
system_prompt: str | None = None,
|
|
379
|
+
) -> str: ...
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
This makes it easy to:
|
|
383
|
+
|
|
384
|
+
- switch providers
|
|
385
|
+
- test providers
|
|
386
|
+
- implement custom providers
|
|
387
|
+
- support enterprise LLMs
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
# Project Structure
|
|
392
|
+
|
|
393
|
+
```text
|
|
394
|
+
pyrestkit/
|
|
395
|
+
│
|
|
396
|
+
├── pyrestkit/
|
|
397
|
+
│ │
|
|
398
|
+
│ ├── auth/
|
|
399
|
+
│ ├── client/
|
|
400
|
+
│ ├── config/
|
|
401
|
+
│ ├── exceptions/
|
|
402
|
+
│ ├── logging/
|
|
403
|
+
│ ├── retry/
|
|
404
|
+
│ ├── validators/
|
|
405
|
+
│ │
|
|
406
|
+
│ ├── ai/
|
|
407
|
+
│ │ ├── analyzer.py
|
|
408
|
+
│ │ ├── config.py
|
|
409
|
+
│ │ ├── exceptions.py
|
|
410
|
+
│ │ ├── factory.py
|
|
411
|
+
│ │ ├── prompt_loader.py
|
|
412
|
+
│ │ ├── prompts/
|
|
413
|
+
│ │ └── providers/
|
|
414
|
+
│ │
|
|
415
|
+
│ └── ...
|
|
416
|
+
│
|
|
417
|
+
├── docs/
|
|
418
|
+
├── examples/
|
|
419
|
+
├── tests/
|
|
420
|
+
├── pyproject.toml
|
|
421
|
+
└── README.md
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
# Framework Architecture
|
|
427
|
+
|
|
428
|
+
```text
|
|
429
|
+
Test
|
|
430
|
+
|
|
431
|
+
│
|
|
432
|
+
|
|
433
|
+
▼
|
|
434
|
+
|
|
435
|
+
API Client
|
|
436
|
+
|
|
437
|
+
│
|
|
438
|
+
|
|
439
|
+
▼
|
|
440
|
+
|
|
441
|
+
Authentication Layer
|
|
442
|
+
|
|
443
|
+
│
|
|
444
|
+
|
|
445
|
+
▼
|
|
446
|
+
|
|
447
|
+
HTTP Transport
|
|
448
|
+
|
|
449
|
+
│
|
|
450
|
+
|
|
451
|
+
▼
|
|
452
|
+
|
|
453
|
+
API Response
|
|
454
|
+
|
|
455
|
+
│
|
|
456
|
+
|
|
457
|
+
┌──────────┴──────────┐
|
|
458
|
+
|
|
459
|
+
▼ ▼
|
|
460
|
+
|
|
461
|
+
Validation AI Analysis
|
|
462
|
+
|
|
463
|
+
│ │
|
|
464
|
+
|
|
465
|
+
▼ ▼
|
|
466
|
+
|
|
467
|
+
Assertions Root Cause Analysis
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
# Why AI Is Optional
|
|
473
|
+
|
|
474
|
+
PyRestKit is designed as an API automation framework first.
|
|
475
|
+
|
|
476
|
+
AI is an optional capability.
|
|
477
|
+
|
|
478
|
+
This provides several advantages:
|
|
479
|
+
|
|
480
|
+
- no AI dependency for normal users
|
|
481
|
+
- predictable execution
|
|
482
|
+
- no external API calls unless enabled
|
|
483
|
+
- works in offline environments
|
|
484
|
+
- enterprise friendly
|
|
485
|
+
- easier testing
|
|
486
|
+
|
|
487
|
+
If AI is never configured, PyRestKit behaves exactly like a traditional API
|
|
488
|
+
automation framework.
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
# Extending PyRestKit
|
|
493
|
+
|
|
494
|
+
Creating a custom AI provider requires implementing a single interface.
|
|
495
|
+
|
|
496
|
+
```python
|
|
497
|
+
from pyrestkit.ai.providers.base import BaseAIProvider
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
class InternalProvider(BaseAIProvider):
|
|
501
|
+
def complete(
|
|
502
|
+
self,
|
|
503
|
+
prompt: str,
|
|
504
|
+
*,
|
|
505
|
+
config,
|
|
506
|
+
system_prompt=None,
|
|
507
|
+
) -> str:
|
|
508
|
+
|
|
509
|
+
...
|
|
510
|
+
|
|
511
|
+
return result
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Register the provider.
|
|
515
|
+
|
|
516
|
+
```python
|
|
517
|
+
factory.register(
|
|
518
|
+
"internal",
|
|
519
|
+
InternalProvider,
|
|
520
|
+
)
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
Now it can be used exactly like built-in providers.
|
|
524
|
+
|
|
525
|
+
---
|
|
526
|
+
|
|
527
|
+
# Example Workflow
|
|
528
|
+
|
|
529
|
+
```python
|
|
530
|
+
response = client.post(
|
|
531
|
+
"/users",
|
|
532
|
+
json=payload,
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
response.validate_status_code(201)
|
|
536
|
+
|
|
537
|
+
response.validate_schema("schemas/user.json")
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
If validation fails:
|
|
541
|
+
|
|
542
|
+
```python
|
|
543
|
+
analysis = analyzer.analyze(
|
|
544
|
+
request=request,
|
|
545
|
+
response=response,
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
print(analysis)
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Example output:
|
|
552
|
+
|
|
553
|
+
```text
|
|
554
|
+
Status Code Mismatch
|
|
555
|
+
|
|
556
|
+
Expected:
|
|
557
|
+
201
|
|
558
|
+
|
|
559
|
+
Received:
|
|
560
|
+
400
|
|
561
|
+
|
|
562
|
+
Likely Cause
|
|
563
|
+
|
|
564
|
+
The "email" field is required but missing
|
|
565
|
+
from the request payload.
|
|
566
|
+
|
|
567
|
+
Suggested Fix
|
|
568
|
+
|
|
569
|
+
Include a valid email address before
|
|
570
|
+
submitting the request.
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
# Documentation
|
|
576
|
+
|
|
577
|
+
Detailed documentation is available in the `docs` directory.
|
|
578
|
+
|
|
579
|
+
| Document | Description |
|
|
580
|
+
|----------|-------------|
|
|
581
|
+
| getting-started.md | Installation and first project |
|
|
582
|
+
| architecture.md | Internal framework architecture |
|
|
583
|
+
| configuration.md | Configuration system |
|
|
584
|
+
| authentication.md | Authentication mechanisms |
|
|
585
|
+
| validation.md | Validators and assertions |
|
|
586
|
+
| ai.md | AI-assisted failure analysis |
|
|
587
|
+
| providers.md | AI provider implementations |
|
|
588
|
+
| examples.md | Complete usage examples |
|
|
589
|
+
| faq.md | Frequently asked questions |
|
|
590
|
+
| roadmap.md | Future development plans |
|
|
591
|
+
|
|
592
|
+
---
|
|
593
|
+
|
|
594
|
+
# Running Tests
|
|
595
|
+
|
|
596
|
+
Run all tests.
|
|
597
|
+
|
|
598
|
+
```bash
|
|
599
|
+
pytest
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
Run with coverage.
|
|
603
|
+
|
|
604
|
+
```bash
|
|
605
|
+
pytest --cov=pyrestkit
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
Run Ruff.
|
|
609
|
+
|
|
610
|
+
```bash
|
|
611
|
+
ruff check .
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Run MyPy.
|
|
615
|
+
|
|
616
|
+
```bash
|
|
617
|
+
mypy .
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Build package.
|
|
621
|
+
|
|
622
|
+
```bash
|
|
623
|
+
python -m build
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
---
|
|
627
|
+
|
|
628
|
+
# Contributing
|
|
629
|
+
|
|
630
|
+
Contributions are welcome.
|
|
631
|
+
|
|
632
|
+
Please read:
|
|
633
|
+
|
|
634
|
+
- CONTRIBUTING.md
|
|
635
|
+
- CODE_OF_CONDUCT.md
|
|
636
|
+
|
|
637
|
+
before submitting pull requests.
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
# Roadmap
|
|
642
|
+
|
|
643
|
+
## Version 1.x
|
|
644
|
+
|
|
645
|
+
- REST API Client
|
|
646
|
+
- Authentication
|
|
647
|
+
- Validation
|
|
648
|
+
- Assertions
|
|
649
|
+
- Retry
|
|
650
|
+
- Configuration
|
|
651
|
+
- Logging
|
|
652
|
+
- AI Failure Analysis
|
|
653
|
+
- Multiple AI Providers
|
|
654
|
+
|
|
655
|
+
## Version 2.x
|
|
656
|
+
|
|
657
|
+
Planned improvements include:
|
|
658
|
+
|
|
659
|
+
- Async HTTP Client
|
|
660
|
+
- HTML Reporting
|
|
661
|
+
- OpenAPI Integration
|
|
662
|
+
- AI Test Generation
|
|
663
|
+
- AI Assertion Suggestions
|
|
664
|
+
- Plugin System
|
|
665
|
+
- CLI
|
|
666
|
+
- VS Code Extension
|
|
667
|
+
|
|
668
|
+
---
|
|
669
|
+
|
|
670
|
+
# Why PyRestKit?
|
|
671
|
+
|
|
672
|
+
PyRestKit aims to provide a clean, extensible, and modern approach to REST API automation.
|
|
673
|
+
|
|
674
|
+
Core principles:
|
|
675
|
+
|
|
676
|
+
- Simplicity
|
|
677
|
+
- Type Safety
|
|
678
|
+
- Extensibility
|
|
679
|
+
- Clean Architecture
|
|
680
|
+
- Optional AI
|
|
681
|
+
- Developer Experience
|
|
682
|
+
|
|
683
|
+
---
|
|
684
|
+
|
|
685
|
+
# Requirements
|
|
686
|
+
|
|
687
|
+
- Python 3.10+
|
|
688
|
+
- requests
|
|
689
|
+
- pydantic
|
|
690
|
+
- jsonschema
|
|
691
|
+
- PyYAML
|
|
692
|
+
|
|
693
|
+
Optional:
|
|
694
|
+
|
|
695
|
+
- OpenAI
|
|
696
|
+
- Anthropic
|
|
697
|
+
- Gemini
|
|
698
|
+
- Azure OpenAI
|
|
699
|
+
- Groq
|
|
700
|
+
- Cohere
|
|
701
|
+
- Mistral
|
|
702
|
+
- Ollama
|
|
703
|
+
- AWS Bedrock
|
|
704
|
+
|
|
705
|
+
---
|
|
706
|
+
|
|
707
|
+
# License
|
|
708
|
+
|
|
709
|
+
PyRestKit is licensed under the MIT License.
|
|
710
|
+
|
|
711
|
+
See the LICENSE file for details.
|
|
712
|
+
|
|
713
|
+
---
|
|
714
|
+
|
|
715
|
+
# Support
|
|
716
|
+
|
|
717
|
+
If you encounter an issue:
|
|
718
|
+
|
|
719
|
+
- Open a GitHub Issue
|
|
720
|
+
- Start a GitHub Discussion
|
|
721
|
+
- Submit a Pull Request
|
|
722
|
+
|
|
723
|
+
---
|
|
724
|
+
|
|
725
|
+
# Acknowledgements
|
|
726
|
+
|
|
727
|
+
PyRestKit is inspired by the design philosophies of several outstanding open-source projects, including:
|
|
728
|
+
|
|
729
|
+
- Requests
|
|
730
|
+
- HTTPX
|
|
731
|
+
- FastAPI
|
|
732
|
+
- Pydantic
|
|
733
|
+
- Playwright
|
|
734
|
+
|
|
735
|
+
while focusing specifically on delivering a modern, extensible framework for REST API automation.
|
|
736
|
+
|
|
737
|
+
---
|
|
738
|
+
|
|
739
|
+
## Star the Project ⭐
|
|
740
|
+
|
|
741
|
+
If PyRestKit helps your team build reliable API automation, consider starring the repository to support the project and stay updated with future releases.
|