HTTPretty: Intercepting HTTP Requests for Python Testing

This repository profile is provided by osrepos.com, an open source repository discovery platform.

HTTPretty: Intercepting HTTP Requests for Python Testing

Summary

HTTPretty is a powerful Python library designed to intercept HTTP requests at the socket level, effectively faking the entire socket module. It provides a robust solution for mocking external HTTP services, making it ideal for test-driven development and reliable API integration testing. Developers can use HTTPretty to simulate various HTTP responses, ensuring comprehensive and isolated testing environments.

Repository Information

Analyzed by OSRepos on August 3, 2026

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

HTTPretty is a Python library created by Gabriel Falcão that provides a comprehensive solution for mocking HTTP client requests. It operates by intercepting HTTP requests at the Python socket level, effectively faking the entire socket module. This capability makes HTTPretty an invaluable tool for developers working on API integrations, enabling them to simulate external service responses without making actual network calls. Inspired by FakeWeb, HTTPretty simplifies the process of creating isolated and repeatable tests for applications that interact with web services.

Installation

To get started with HTTPretty, you can easily install it using pip:

pip install httpretty

Examples

Simple Example

This example demonstrates how to register a GET request and assert the response and request details.

import sure
import httpretty
import requests


@httpretty.activate(verbose=True, allow_net_connect=False)
def test_httpbin():
    httpretty.register_uri(
        httpretty.GET,
        "https://httpbin.org/ip",
        body='{"origin": "127.0.0.1"}'
    )

    response = requests.get('https://httpbin.org/ip')
    response.json().should.equal({'origin': '127.0.0.1'})

    httpretty.latest_requests().should.have.length_of(1)
    httpretty.last_request().should.equal(httpretty.latest_requests()[0])
    httpretty.last_request().body.should.equal('{"origin": "127.0.0.1"}')

Checking Multiple Responses

This example shows how to register multiple responses for the same URL and verify the request bodies.

@httpretty.activate(verbose=True, allow_net_connect=False)
def test_post_bodies():
    url = 'http://httpbin.org/post'
    httpretty.register_uri(httpretty.POST, url, status=200)
    httpretty.register_uri(httpretty.POST, url, status=400)
    requests.post(url, data={'foo': 'bar'})
    requests.post(url, data={'zoo': 'zoo'})
    assert 'foo=bar' in httpretty.latest_requests()[0].body
    assert 'zoo=bar' in httpretty.latest_requests()[1].body

Why Use HTTPretty?

HTTPretty is essential for robust software development, especially when dealing with external APIs. Its primary benefits include:

  • Test-Driven Development (TDD) of API Integrations: Facilitates writing tests for API clients before or during implementation, ensuring correct behavior.
  • Faking Responses of External APIs: Allows developers to simulate various API responses, including success, failure, and edge cases, without relying on actual external services.
  • Recording and Playback of HTTP Requests: Useful for debugging, performance testing, and creating repeatable test scenarios.
  • Isolation and Speed: By intercepting requests at the socket level, HTTPretty ensures tests are isolated from network latency and external service availability, leading to faster and more reliable test suites.

Links

Related repositories

Similar repositories that may be relevant next.

oh-my-hermes: Enhance Hermes Agent with Advanced AI Workflow and Memory

oh-my-hermes: Enhance Hermes Agent with Advanced AI Workflow and Memory

September 17, 2026

oh-my-hermes is an all-in-one plugin designed to significantly enhance the Hermes Agent. It provides advanced coding intelligence, a robust long-term memory system, and optimized workflow packages, transforming standard Hermes requests into structured, actionable tasks with clear operational layers.

AI AgentHermes AgentAI Tools
ASC: A Super Fast Android Decompiler for Mobile Reverse Engineering

ASC: A Super Fast Android Decompiler for Mobile Reverse Engineering

September 17, 2026

ASC is an innovative and exceptionally fast Android decompiler front-end, specifically designed for mobile researchers and agents. It redefines traditional decompilation by directly querying compiled artifacts, offering on-demand code extraction and analysis without heavy preprocessing. This approach results in significantly reduced memory usage and lightning-fast performance, even on large APKs.

AndroidDecompilerReverse Engineering
Open Index: A Deterministic Memory Layer for Your AI Agents

Open Index: A Deterministic Memory Layer for Your AI Agents

September 16, 2026

Open Index is a powerful tool for building domain-specific, accurate, and structured data that AI agents can effectively operate on. It enables the creation of a "brain," a searchable and continuously improving context graph tailored to any domain. This system ensures agents have access to reliable, up-to-date information, enhancing their capabilities and decision-making processes.

AI AgentsKnowledge GraphAgent Memory
tooltrim: Drastically Reduce LLM Agent Tool Output Tokens, Improve Accuracy

tooltrim: Drastically Reduce LLM Agent Tool Output Tokens, Improve Accuracy

September 16, 2026

tooltrim provides drop-in compression for LLM agent tool outputs, drastically cutting tokens while often improving answer accuracy. This provider-agnostic solution offers content-aware compression, faithfulness benchmarks, and seamless integration with popular frameworks or as an OpenAI-compatible proxy.

PythonLLM AgentsContext Compression

Source repository

Open the original repository on GitHub.

23 counted GitHub visits

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️