Modern Python REST API Automation Toolkit With AI
Project description
๐ PyRestKit
A modern Python framework for REST API automation with built-in validation, authentication, configuration management, and optional AI-assisted failure analysis.
Why PyRestKit?
Testing REST APIs often requires combining multiple libraries for:
- HTTP requests
- Authentication
- Configuration management
- Assertions
- JSON validation
- Logging
- Retry handling
- Environment management
As projects grow, these utilities become difficult to maintain consistently across teams.
PyRestKit provides a unified, extensible framework that brings these capabilities together while keeping your test code clean, maintainable, and type-safe.
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.
Features
REST API Client
- Simple request API
- GET / POST / PUT / PATCH / DELETE
- Custom headers
- Query parameters
- Cookies
- Multipart requests
- Request timeout support
Authentication
Built-in authentication helpers:
- Basic Authentication
- Bearer Token
- API Key
- OAuth 2.0 (yet to implement)
- Custom authentication strategies
Validation
Powerful response validation utilities.
Supported validations include:
- Status Code
- Headers
- JSON Schema
- Response Time
- JSON Path
- Custom Validators
Configuration
Configuration can be loaded from
- YAML
- Environment Variables
- Python Objects
Supports multiple environments including
- Development
- QA
- Staging
- Production
Assertions
Readable assertions for
- Status codes
- Headers
- JSON values
- Collections
- Response time
- Custom assertions
AI-Assisted Failure Analysis
PyRestKit can analyze failed API responses using AI.
Features include
- Root cause explanation
- Human-readable summaries
- Suggested fixes
- Optional system prompts
- Prompt templates
- Provider abstraction
AI support is completely optional and does not affect users who prefer traditional API testing.
Multiple AI Providers
PyRestKit currently supports:
| Provider | Supported |
|---|---|
| OpenAI | โ |
| Anthropic | โ |
| Google Gemini | โ |
| Azure OpenAI | โ |
| Groq | โ |
| Cohere | โ |
| Mistral | โ |
| Ollama | โ |
| AWS Bedrock | โ |
The provider abstraction allows additional providers to be implemented with minimal effort.
Installation
Standard Installation
pip install pyrestkit
Development Installation
git clone https://github.com/Raushanraj77/pyrestkit.git
cd pyrestkit
python -m venv .venv
source .venv/bin/activate
pip install -e .
Verify Installation
import pyrestkit
print(pyrestkit.__version__)
Quick Start
Create a Client
from pyrestkit import APIClient
client = APIClient(base_url="https://jsonplaceholder.typicode.com")
Send a Request
response = client.get("/posts/1")
Validate Response
response.validate_status_code(200)
response.validate_json()
response.validate_response_time(max_time_ms=1000)
Read JSON
data = response.json()
print(data["title"])
Authentication Example
Bearer Token
client = APIClient(base_url="https://example.com")
client.authenticate_bearer(token="your-token")
Basic Authentication
client.authenticate_basic(username="admin", password="secret")
API Key
client.authenticate_api_key(key="xxxxxxxx", header_name="X-API-Key")
Configuration Example
Load configuration from YAML.
base_url: https://api.example.com
timeout: 30
headers:
Accept: application/json
from pyrestkit.config import Config
config = Config.from_yaml("config.yaml")
Response Validation
response.validate_status_code(200)
response.validate_header("Content-Type", "application/json")
response.validate_schema("schemas/user.json")
AI Failure Analysis
AI analysis can be enabled whenever deeper insight into a failed response is useful.
from pyrestkit.ai import AIAnalyzer
from pyrestkit.ai import AIConfig
config = AIConfig(provider="openai", model="gpt-4.1-mini", api_key="YOUR_API_KEY")
analyzer = AIAnalyzer(config)
analysis = analyzer.analyze(
request=request,
response=response,
)
print(analysis)
Supported AI Providers
PyRestKit uses a provider abstraction layer that allows switching AI providers without changing your test code.
AI Analyzer
โ
โผ
Provider Factory
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โผ โผ โผ
OpenAI Anthropic Gemini
โ โ โ
โผ โผ โผ
Groq Cohere Azure OpenAI
โ
โผ
Mistral
โ
โผ
Ollama
โ
โผ
AWS Bedrock
Every provider implements the same interface.
class BaseAIProvider:
def complete(
self,
prompt: str,
*,
config: AIConfig,
system_prompt: str | None = None,
) -> str: ...
This makes it easy to:
- switch providers
- test providers
- implement custom providers
- support enterprise LLMs
Project Structure
pyrestkit/
โ
โโโ pyrestkit/
โ โ
โ โโโ auth/
โ โโโ client/
โ โโโ config/
โ โโโ exceptions/
โ โโโ logging/
โ โโโ retry/
โ โโโ validators/
โ โ
โ โโโ ai/
โ โ โโโ analyzer.py
โ โ โโโ config.py
โ โ โโโ exceptions.py
โ โ โโโ factory.py
โ โ โโโ prompt_loader.py
โ โ โโโ prompts/
โ โ โโโ providers/
โ โ
โ โโโ ...
โ
โโโ docs/
โโโ examples/
โโโ tests/
โโโ pyproject.toml
โโโ README.md
Framework Architecture
Test
โ
โผ
API Client
โ
โผ
Authentication Layer
โ
โผ
HTTP Transport
โ
โผ
API Response
โ
โโโโโโโโโโโโดโโโโโโโโโโโ
โผ โผ
Validation AI Analysis
โ โ
โผ โผ
Assertions Root Cause Analysis
Why AI Is Optional
PyRestKit is designed as an API automation framework first.
AI is an optional capability.
This provides several advantages:
- no AI dependency for normal users
- predictable execution
- no external API calls unless enabled
- works in offline environments
- enterprise friendly
- easier testing
If AI is never configured, PyRestKit behaves exactly like a traditional API automation framework.
Extending PyRestKit
Creating a custom AI provider requires implementing a single interface.
from pyrestkit.ai.providers.base import BaseAIProvider
class InternalProvider(BaseAIProvider):
def complete(
self,
prompt: str,
*,
config,
system_prompt=None,
) -> str:
...
return result
Register the provider.
factory.register(
"internal",
InternalProvider,
)
Now it can be used exactly like built-in providers.
Example Workflow
response = client.post(
"/users",
json=payload,
)
response.validate_status_code(201)
response.validate_schema("schemas/user.json")
If validation fails:
analysis = analyzer.analyze(
request=request,
response=response,
)
print(analysis)
Example output:
Status Code Mismatch
Expected:
201
Received:
400
Likely Cause
The "email" field is required but missing
from the request payload.
Suggested Fix
Include a valid email address before
submitting the request.
Documentation
Detailed documentation is available in the docs directory.
| Document | Description |
|---|---|
| getting-started.md | Installation and first project |
| architecture.md | Internal framework architecture |
| configuration.md | Configuration system |
| authentication.md | Authentication mechanisms |
| validation.md | Validators and assertions |
| ai.md | AI-assisted failure analysis |
| providers.md | AI provider implementations |
| examples.md | Complete usage examples |
| faq.md | Frequently asked questions |
| roadmap.md | Future development plans |
Running Tests
Run all tests.
pytest
Run with coverage.
pytest --cov=pyrestkit
Run Ruff.
ruff check .
Run MyPy.
mypy .
Build package.
python -m build
Contributing
Contributions are welcome.
Please read:
- CONTRIBUTING.md
- CODE_OF_CONDUCT.md
before submitting pull requests.
Roadmap
Version 1.x
- REST API Client
- Authentication
- Validation
- Assertions
- Retry
- Configuration
- Logging
- AI Failure Analysis
- Multiple AI Providers
Version 2.x
Planned improvements include:
- Async HTTP Client
- HTML Reporting
- OpenAPI Integration
- AI Test Generation
- AI Assertion Suggestions
- Plugin System
- CLI
- VS Code Extension
Why PyRestKit?
PyRestKit aims to provide a clean, extensible, and modern approach to REST API automation.
Core principles:
- Simplicity
- Type Safety
- Extensibility
- Clean Architecture
- Optional AI
- Developer Experience
Requirements
- Python 3.10+
- requests
- pydantic
- jsonschema
- PyYAML
Optional:
- OpenAI
- Anthropic
- Gemini
- Azure OpenAI
- Groq
- Cohere
- Mistral
- Ollama
- AWS Bedrock
License
PyRestKit is licensed under the MIT License.
See the LICENSE file for details.
Support
If you encounter an issue:
- Open a GitHub Issue
- Start a GitHub Discussion
- Submit a Pull Request
Acknowledgements
PyRestKit is inspired by the design philosophies of several outstanding open-source projects, including:
- Requests
- HTTPX
- FastAPI
- Pydantic
- Playwright
while focusing specifically on delivering a modern, extensible framework for REST API automation.
Star the Project โญ
If PyRestKit helps your team build reliable API automation, consider starring the repository to support the project and stay updated with future releases.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyrestkit-1.2.2.tar.gz.
File metadata
- Download URL: pyrestkit-1.2.2.tar.gz
- Upload date:
- Size: 71.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a9d56b29aaf13f26f4afe3b7cf9786b06a71b0a6ee129ac40f4a8caf670ac5c
|
|
| MD5 |
96cc30ea54d69d8988d809147c846548
|
|
| BLAKE2b-256 |
21b8288ae4afcc0ad40a722d88b93a247aa326972dca27efd59ec19ec3db78c4
|
Provenance
The following attestation bundles were made for pyrestkit-1.2.2.tar.gz:
Publisher:
release.yml on Raushanraj77/pyrestkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrestkit-1.2.2.tar.gz -
Subject digest:
2a9d56b29aaf13f26f4afe3b7cf9786b06a71b0a6ee129ac40f4a8caf670ac5c - Sigstore transparency entry: 2081611325
- Sigstore integration time:
-
Permalink:
Raushanraj77/pyrestkit@94ae1bf1df90033e3e97f36354c795ffdcfc6ba5 -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/Raushanraj77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@94ae1bf1df90033e3e97f36354c795ffdcfc6ba5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrestkit-1.2.2-py3-none-any.whl.
File metadata
- Download URL: pyrestkit-1.2.2-py3-none-any.whl
- Upload date:
- Size: 64.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d39efae3c429b2b1d500118bb6789ec2e42d2f1d68dc854ef8d03e22e24066bf
|
|
| MD5 |
fd0d71077e85feff18feabd046b308c2
|
|
| BLAKE2b-256 |
bbde8d4e934b52b50c04e4e267322fd7d9e576e205372d8c4c8e365acebb6f67
|
Provenance
The following attestation bundles were made for pyrestkit-1.2.2-py3-none-any.whl:
Publisher:
release.yml on Raushanraj77/pyrestkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrestkit-1.2.2-py3-none-any.whl -
Subject digest:
d39efae3c429b2b1d500118bb6789ec2e42d2f1d68dc854ef8d03e22e24066bf - Sigstore transparency entry: 2081611380
- Sigstore integration time:
-
Permalink:
Raushanraj77/pyrestkit@94ae1bf1df90033e3e97f36354c795ffdcfc6ba5 -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/Raushanraj77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@94ae1bf1df90033e3e97f36354c795ffdcfc6ba5 -
Trigger Event:
push
-
Statement type: