AI-powered validation wrapper for Python requests library
Project description
🤖 requests-ai-validator
AI-powered REST API testing framework - drop-in replacement for requests with intelligent validation
🎯 What is it?
requests-ai-validator is a drop-in replacement for the popular requests library that adds AI-powered validation capabilities to your REST API tests. It uses Large Language Models (LLMs) to intelligently validate API responses, request-response consistency, and business logic.
✨ Key Features
- 🔄 Drop-in replacement for
requests- change only the import statement - 🤖 AI-powered validation - intelligent analysis of API interactions
- 📊 Multiple AI providers - OpenAI, Anthropic, Ollama support
- 🎯 Schema validation - Pydantic models, JSON Schema, OpenAPI support
- 🌍 English feedback - clear and professional AI responses
- 📋 Business rules - custom validation rules
- 📊 Allure integration - detailed reporting
- ⚙️ Environment configuration - easy setup via .env
🚀 Quick Start
Installation
pip install requests-ai-validator
Basic Usage
# Replace this line:
import requests
# With this line:
import requests_ai_validator as requests
# Use exactly like regular requests + AI validation:
from pydantic import BaseModel
class UserModel(BaseModel):
id: int
name: str
email: str
# Regular request
response = requests.get("https://api.example.com/users/1")
# With AI validation - just add parameters!
response = requests.get(
"https://api.example.com/users/1",
ai_validation=True,
ai_schema=UserModel,
ai_rules=["User must exist and be valid"]
)
# If AI finds issues → test fails with detailed feedback
⚙️ Configuration
Environment Variables (.env)
# AI Configuration
AI_TOKEN=your-api-key-here
AI_PROVIDER=openai
AI_MODEL=gpt-3.5-turbo
Supported Providers
| Provider | Models | API Key |
|---|---|---|
| OpenAI | gpt-3.5-turbo, gpt-4, gpt-4-turbo, gpt-4o | AI_TOKEN |
| Anthropic | claude-3-haiku, claude-3-sonnet, claude-3-opus | AI_TOKEN |
| Ollama | llama2, codellama, mistral | No API key (local) |
Language
All AI feedback is provided in English for universal compatibility and clarity.
📖 Usage Examples
1. Simple GET Request
import requests_ai_validator as requests
from pydantic import BaseModel
class UserModel(BaseModel):
id: int
name: str
email: str
# AI validation built into the request
response = requests.get(
"https://api.example.com/users/1",
ai_validation=True,
ai_schema=UserModel
)
2. POST Request with Business Rules
response = requests.post(
"https://api.example.com/users",
json={"name": "John", "email": "john@example.com"},
ai_validation=True,
ai_schema=UserModel,
ai_rules=[
"User should be successfully created",
"ID should be a positive number"
]
)
3. Session Usage
session = requests.Session(ai_provider="openai")
response = session.get(
url,
ai_validation=True,
ai_schema=Model
)
4. Manual Configuration
# Override environment settings
requests.configure_global_ai(
ai_provider="anthropic",
api_key="your-claude-key",
model="claude-3-sonnet"
)
🎯 AI Validation Categories
The AI validates 5 key areas:
| Category | Description | Example |
|---|---|---|
| http_compliance | HTTP protocol validation | "Status code 200 correct for GET request" |
| request_validation | Request payload validation | "Request contains valid data: name, email" |
| response_structure | Response format validation | "Response has valid JSON structure" |
| schema_compliance | Schema adherence | "All required fields present in response" |
| data_consistency | Request-response consistency | "Common fields match: name, email" |
❌ Error Handling
When AI validation fails, you get detailed feedback:
AssertionError: ❌ AI validation failed: Schema validation issues found.
{'schema_compliance': "Missing required field 'missing_field' in response", 'data_consistency': 'Request field name does not match response'}
🔧 Advanced Usage
Positive vs Negative Tests
# Positive test - expect AI to find no issues
response = requests.get(url, ai_validation=True, expected_result=True)
# Negative test - expect AI to find issues
response = requests.get(url, ai_validation=True, expected_result=False)
Custom AI Instructions
response = requests.post(
url,
json=data,
ai_validation=True,
ai_schema=Model,
ai_rules=["Business rule 1", "Business rule 2"],
ai_instructions=["Focus on data consistency", "Ignore performance"]
)
📊 Integration with Existing Code
Minimal Changes Required
# Before:
import requests
response = requests.get(url)
assert response.status_code == 200
return Model(**response.json())
# After:
import requests_ai_validator as requests # Only this line changed
response = requests.get(url, ai_validation=True, ai_schema=Model) # Added AI validation
assert response.status_code == 200
return Model(**response.json())
Framework Integration
Works seamlessly with popular testing frameworks:
- ✅ pytest - automatic test failure on AI issues
- ✅ Allure - detailed AI feedback in reports
- ✅ unittest - standard assertions work
- ✅ Custom frameworks - minimal integration effort
🔍 How It Works
- Make request - uses standard
requestslibrary - AI analysis - sends request/response to LLM for validation
- Intelligent feedback - gets structured analysis of API interaction
- Test control - fails test if AI finds issues (configurable)
🎯 Benefits
- 🧠 Intelligent validation - catches issues traditional testing misses
- 🚀 Easy adoption - minimal code changes required
- 🔍 Deep analysis - validates business logic, not just structure
- 📊 Rich feedback - detailed explanations of issues found
- ⚡ Fast integration - works with existing test suites
- 🌍 Multi-language - supports different feedback languages
📋 Requirements
- Python 3.8+
requestslibrarypydanticfor schema validation- AI provider API key (OpenAI, Anthropic) or local Ollama
🔗 Links
- GitHub: Source code
- PyPI: Package
- Issues: Report bugs
- Examples: See
project/directory for integration examples
📄 License
MIT License - see LICENSE file for details.
🎨 Created with
This framework was created with Вайб кодинг - AI-powered development approach that combines human creativity with AI assistance to build elegant and powerful solutions.
Transform your API testing with AI intelligence! 🚀
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 requests_ai_validator-1.0.1.tar.gz.
File metadata
- Download URL: requests_ai_validator-1.0.1.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7df6e994c85fb6505f754e410dc23fa8db7adba3d5d029732b3e47a589898d3
|
|
| MD5 |
54964bd46129dd3554fa0dc837629978
|
|
| BLAKE2b-256 |
12e6329aaa257dea32289bd18a82660e4b2bc63c123b4715b8555c0f18ff6a82
|
Provenance
The following attestation bundles were made for requests_ai_validator-1.0.1.tar.gz:
Publisher:
publish.yml on manikosto/requests-ai-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
requests_ai_validator-1.0.1.tar.gz -
Subject digest:
c7df6e994c85fb6505f754e410dc23fa8db7adba3d5d029732b3e47a589898d3 - Sigstore transparency entry: 417142350
- Sigstore integration time:
-
Permalink:
manikosto/requests-ai-validator@2f8c94a3676864eadb64fae555a5545f26a9bccd -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/manikosto
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2f8c94a3676864eadb64fae555a5545f26a9bccd -
Trigger Event:
release
-
Statement type:
File details
Details for the file requests_ai_validator-1.0.1-py3-none-any.whl.
File metadata
- Download URL: requests_ai_validator-1.0.1-py3-none-any.whl
- Upload date:
- Size: 37.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cab804059e69c89589503baca50331c82e841684df6bd55812098f103b9ea548
|
|
| MD5 |
44cf069f234a349be60cd58026d69c15
|
|
| BLAKE2b-256 |
e5f4d26fd326a81594dbf55b5aa7d5aaf4e9d63040aaa41b839b8f656498e083
|
Provenance
The following attestation bundles were made for requests_ai_validator-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on manikosto/requests-ai-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
requests_ai_validator-1.0.1-py3-none-any.whl -
Subject digest:
cab804059e69c89589503baca50331c82e841684df6bd55812098f103b9ea548 - Sigstore transparency entry: 417142368
- Sigstore integration time:
-
Permalink:
manikosto/requests-ai-validator@2f8c94a3676864eadb64fae555a5545f26a9bccd -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/manikosto
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2f8c94a3676864eadb64fae555a5545f26a9bccd -
Trigger Event:
release
-
Statement type: