Registry / http-networking / httpbin

httpbin

JSON →
library0.10.2pypypi✓ verified 84d ago

httpbin is an open-source HTTP request and response service, implemented in Python using Flask. It provides various endpoints that echo back client requests, return specific status codes, headers, or dynamic data, making it invaluable for testing HTTP clients, debugging webhooks, and understanding HTTP protocol concepts. The current version, 0.10.2, is actively maintained by the Python Software Foundation (PSF) and has seen several recent releases, including a major fork from its original maintainer due to inactivity.

pip install httpbin
INSTALL
IMPORT
SIG · HTTPBIN
H
httpbin
http-networkingpythonv0.10.2
Install
8.7s avg
Import
883ms
Disk
76MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.10.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
build_error
glibc
py 3.103.940 runs
installs and imports cleanly · install 8.7s · import 0.883s · 82MB
76MB installed
● package 76MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

app
from httpbin import app
Used when running httpbin as a WSGI application via a server like Gunicorn.

To use httpbin, you typically run it as a WSGI application. The most common way is with a WSGI server like Gunicorn, which serves the `httpbin:app` object. For development or quick testing, you can also run it directly as a module. The provided code includes instructions for both running the service and a Python example (using the 'requests' library) demonstrating how to interact with an httpbin instance, typically the public httpbin.org service.

import os # To run httpbin as a standalone WSGI application using Gunicorn: # 1. Ensure you have httpbin installed with the 'mainapp' extra: # pip install 'httpbin[mainapp]' gunicorn # 2. Run the following command in your terminal: # gunicorn httpbin:app # Alternatively, for a simple direct run (for development/testing): # 1. Ensure httpbin is installed: # pip install httpbin # 2. Run the following command in your terminal: # python -m httpbin.core # Example of interacting with a running httpbin instance (using requests library): # (This code is for demonstration, it interacts with httpbin.org, not your local instance) import requests base_url = "https://httpbin.org" # Make a GET request and inspect the response response_get = requests.get(f"{base_url}/get?key=value") print(f"GET Status: {response_get.status_code}") print(f"GET JSON: {response_get.json()['args']}") # Make a POST request with JSON data post_data = {"name": "test", "id": 123} response_post = requests.post(f"{base_url}/post", json=post_data) print(f"POST Status: {response_post.status_code}") print(f"POST JSON: {response_post.json()['json']}")
Debug
Known issues
gotchaThe `httpbin` PyPI package (maintained by PSF) is a fork and is NOT the backend for the public service `httpbin.org` (which is run by Postman Labs). Users often confuse the two, leading to potential discrepancies between local test environments and public service behavior.
fix
Be aware of the distinction. For critical testing, consider running a local instance of httpbin from the PSF package instead of relying on the public httpbin.org service.
affects: All versions since the fork (0.10.0+)
gotchaRelying on the public `httpbin.org` service for automated tests can lead to intermittent failures due to network latency, server load, or unexpected changes in `httpbin.org`'s responses (e.g., occasional HTTP vs. HTTPS inconsistencies).
fix
For robust and reliable testing, it is highly recommended to run a local `httpbin` instance (using the PyPI package) within your testing environment, for example, using `pytest-httpbin` or by deploying it with Gunicorn.
affects: N/A (applies to external usage of httpbin.org)
gotchaTo run `httpbin` as a standalone application, you must install it with the `mainapp` extra (e.g., `pip install 'httpbin[mainapp]'`). A basic `pip install httpbin` might not include all necessary dependencies for direct execution or WSGI deployment.
fix
Always install with `pip install 'httpbin[mainapp]'` if you intend to run it as a service or application. If using Gunicorn, ensure Gunicorn is also installed separately.
affects: 0.10.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'httpbin'
Developers often mistake `httpbin` for a client-side Python library to be imported directly to make HTTP requests, rather than understanding it primarily as a web service (httpbin.org) or a Flask application to be run locally.
fix
To make HTTP requests to the `httpbin` service, use an HTTP client library like `requests` and direct your requests to `httpbin.org` or your own deployed `httpbin` instance. If you intend to run the `httpbin` *service* locally, you should typically use Docker or install it and run it with a WSGI server like Gunicorn, not `import httpbin` in your client code. 
```python
import requests
response = requests.get('https://httpbin.org/get')
print(response.json())
```
exec: "gunicorn": executable file not found in $PATH: unknown
This error commonly occurs when running `httpbin` via Docker or a similar containerization technology, indicating that the `gunicorn` web server, which `httpbin` uses, is not found in the container's executable path, often due to an outdated or corrupted image, or incorrect Dockerfile/compose configuration.
fix
Ensure you are using the correct and up-to-date Docker image for `httpbin` (e.g., `ghcr.io/psf/httpbin` or `kennethreitz/httpbin`). If building your own image, verify that `gunicorn` is installed and accessible within the container's environment. For instance, pull the latest official image: 
```bash
docker pull ghcr.io/psf/httpbin
docker run -p 80:8080 ghcr.io/psf/httpbin
```
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='httpbin.org', port=443): Read timed out.
This exception arises when an HTTP client, such as Python's `requests` library, attempts to communicate with `httpbin.org` (or a local instance) but the server does not send any data back within the specified timeout period, often due to network issues, high server load, or intentionally delayed responses from `httpbin` endpoints like `/delay`.
fix
Increase the timeout value in your request or handle the `ReadTimeout` exception gracefully. If using a `/delay` endpoint, adjust the delay or your client's timeout accordingly. Ensure stable network connectivity and consider using a local `httpbin` instance for critical testing. 
```python
import requests

try:
    response = requests.get('https://httpbin.org/delay/5', timeout=10) # Increased timeout
    print(response.json())
except requests.exceptions.ReadTimeout:
    print("Request timed out after 10 seconds.")
```
werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server.
When running a local `httpbin` instance (which is built on Flask/Werkzeug), this error indicates that the client requested an endpoint or URL path that does not exist or is not recognized by the `httpbin` application. This can happen due to typos in the URL or trying to access an endpoint that isn't part of the standard `httpbin` API.
fix
Verify the URL path you are requesting against the available `httpbin` endpoints. Double-check for any typos. If you are running a custom Flask application based on `httpbin`, ensure all routes are correctly defined and accessible. For instance, to access the `/get` endpoint: 
```python
import requests
# Assuming httpbin is running locally on default port 8080
response = requests.get('http://localhost:8080/get')
print(response.json())
```
Upgrade
Version history
0.10.2latest on PyPI · released Feb 20, 2024
Audit
Dependencies
FlaskrequiredCore web framework for the httpbin application.
gunicornoptionalCommonly used WSGI HTTP server to run httpbin as a standalone service.
Agent activity
6 hits · last 30 days
node
6
Resources
httpbin — pip install httpbin · libregistry