Skip to main content

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.

Python PyPI License Tests Code Style Type Checked


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrestkit-1.2.2.tar.gz (71.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrestkit-1.2.2-py3-none-any.whl (64.0 kB view details)

Uploaded Python 3

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

Hashes for pyrestkit-1.2.2.tar.gz
Algorithm Hash digest
SHA256 2a9d56b29aaf13f26f4afe3b7cf9786b06a71b0a6ee129ac40f4a8caf670ac5c
MD5 96cc30ea54d69d8988d809147c846548
BLAKE2b-256 21b8288ae4afcc0ad40a722d88b93a247aa326972dca27efd59ec19ec3db78c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrestkit-1.2.2.tar.gz:

Publisher: release.yml on Raushanraj77/pyrestkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyrestkit-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d39efae3c429b2b1d500118bb6789ec2e42d2f1d68dc854ef8d03e22e24066bf
MD5 fd0d71077e85feff18feabd046b308c2
BLAKE2b-256 bbde8d4e934b52b50c04e4e267322fd7d9e576e205372d8c4c8e365acebb6f67

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrestkit-1.2.2-py3-none-any.whl:

Publisher: release.yml on Raushanraj77/pyrestkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page