httpx

A next-generation HTTP client for Python with both sync and async support, perfect for modern Python applications

25 stars

Best use case

httpx is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

A next-generation HTTP client for Python with both sync and async support, perfect for modern Python applications

Teams using httpx should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/httpx/SKILL.md --create-dirs "https://raw.githubusercontent.com/ComeOnOliver/skillshub/main/skills/aiskillstore/marketplace/bossjones/httpx/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/httpx/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How httpx Compares

Feature / AgenthttpxStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

A next-generation HTTP client for Python with both sync and async support, perfect for modern Python applications

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# HTTPX Skill

HTTPX is a fully featured HTTP client for Python that provides both synchronous and asynchronous APIs, with support for HTTP/1.1 and HTTP/2.

## Quick Start

### Basic Usage

```python
import httpx

# Simple GET request
response = httpx.get('https://api.example.com/data')
print(response.status_code)
print(response.json())

# POST request with JSON data
response = httpx.post('https://api.example.com/users', json={'name': 'Alice'})
```

### Async Usage

```python
import asyncio
import httpx

async def fetch_data():
    async with httpx.AsyncClient() as client:
        response = await client.get('https://api.example.com/data')
        return response.json()

result = asyncio.run(fetch_data())
```

## Common Patterns

### 1. Async Client with Connection Pooling

```python
import httpx

async def make_multiple_requests():
    async with httpx.AsyncClient() as client:
        # Reuse the same client for multiple requests
        tasks = [
            client.get('https://api.example.com/users/1'),
            client.get('https://api.example.com/users/2'),
            client.get('https://api.example.com/users/3')
        ]
        responses = await asyncio.gather(*tasks)
        return [r.json() for r in responses]
```

### 2. Authentication

```python
import httpx

# Basic Authentication
auth = httpx.BasicAuth(username='user', password='pass')
client = httpx.Client(auth=auth)

# Bearer Token Authentication
headers = {'Authorization': 'Bearer your-token-here'}
client = httpx.Client(headers=headers)

# Per-request authentication
response = client.get('https://api.example.com', auth=('user', 'pass'))
```

### 3. Streaming Downloads

```python
import httpx

# Stream large files without loading into memory
with httpx.stream('GET', 'https://example.com/large-file.zip') as response:
    with open('large-file.zip', 'wb') as f:
        for chunk in response.iter_bytes():
            f.write(chunk)

# Async streaming
async def download_large_file():
    async with httpx.AsyncClient() as client:
        async with client.stream('GET', 'https://example.com/large-file.zip') as response:
            with open('large-file.zip', 'wb') as f:
                async for chunk in response.aiter_bytes():
                    f.write(chunk)
```

### 4. Streaming Uploads

```python
import httpx

# Upload large files with streaming
async def upload_large_file():
    def generate_data():
        # Yield chunks of data
        for i in range(100):
            yield f'chunk {i}\n'.encode()

    async with httpx.AsyncClient() as client:
        response = await client.post(
            'https://api.example.com/upload',
            content=generate_data()
        )
        return response
```

### 5. Error Handling and Timeouts

```python
import httpx

# Configure timeouts
client = httpx.Client(
    timeout=httpx.Timeout(10.0, connect=5.0, read=8.0)
)

try:
    response = client.get('https://api.example.com/slow')
    response.raise_for_status()  # Raise exception for 4XX/5XX responses
except httpx.TimeoutException:
    print("Request timed out")
except httpx.HTTPStatusError as e:
    print(f"HTTP error: {e.response.status_code}")
except httpx.RequestError as e:
    print(f"Request failed: {e}")
```

### 6. Client Configuration

```python
import httpx

# Client with shared configuration
client = httpx.Client(
    base_url='https://api.example.com',
    headers={'User-Agent': 'MyApp/1.0'},
    timeout=30.0,
    follow_redirects=True
)

# All requests will use base_url and headers
response = client.get('/users')  # Makes request to https://api.example.com/users
```

### 7. Custom Authentication

```python
import httpx

class CustomAuth(httpx.Auth):
    def __init__(self, api_key):
        self.api_key = api_key

    def auth_flow(self, request):
        request.headers['X-API-Key'] = self.api_key
        yield request

# Use custom auth
auth = CustomAuth('your-secret-api-key')
client = httpx.Client(auth=auth)
```

### 8. Progress Monitoring

```python
import httpx
from tqdm import tqdm

def download_with_progress(url, filename):
    with httpx.stream('GET', url) as response:
        total = int(response.headers.get('content-length', 0))

        with tqdm(total=total, unit='B', unit_scale=True) as progress:
            with open(filename, 'wb') as f:
                for chunk in response.iter_bytes():
                    f.write(chunk)
                    progress.update(len(chunk))
```

### 9. Retry Logic

```python
import httpx
import time

def make_request_with_retry(url, max_retries=3):
    for attempt in range(max_retries):
        try:
            response = httpx.get(url, timeout=10.0)
            response.raise_for_status()
            return response
        except httpx.RequestError as e:
            if attempt == max_retries - 1:
                raise
            time.sleep(2 ** attempt)  # Exponential backoff
```

### 10. WebSocket Support (with httpx-ws)

```python
import httpx
from httpx_ws import connect_ws

async def websocket_example():
    async with httpx.AsyncClient() as client:
        async with connect_ws('wss://echo.websocket.org', client) as websocket:
            await websocket.send_text('Hello, WebSocket!')
            message = await websocket.receive_text()
            print(f"Received: {message}")
```

## Practical Code Snippets

### API Client Class

```python
import httpx
from typing import Optional, Dict, Any

class APIClient:
    def __init__(self, base_url: str, api_key: str):
        self.base_url = base_url
        self.client = httpx.Client(
            base_url=base_url,
            headers={'Authorization': f'Bearer {api_key}'},
            timeout=30.0
        )

    def get(self, endpoint: str, params: Optional[Dict] = None) -> Dict[Any, Any]:
        response = self.client.get(endpoint, params=params)
        response.raise_for_status()
        return response.json()

    def post(self, endpoint: str, data: Dict[Any, Any]) -> Dict[Any, Any]:
        response = self.client.post(endpoint, json=data)
        response.raise_for_status()
        return response.json()

    def close(self):
        self.client.close()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close()

# Usage
with APIClient('https://api.example.com', 'your-api-key') as client:
    users = client.get('/users')
    new_user = client.post('/users', {'name': 'John', 'email': 'john@example.com'})
```

### Async API Client

```python
import httpx
from typing import Optional, Dict, Any

class AsyncAPIClient:
    def __init__(self, base_url: str, api_key: str):
        self.base_url = base_url
        self.client = httpx.AsyncClient(
            base_url=base_url,
            headers={'Authorization': f'Bearer {api_key}'},
            timeout=30.0
        )

    async def get(self, endpoint: str, params: Optional[Dict] = None) -> Dict[Any, Any]:
        response = await self.client.get(endpoint, params=params)
        response.raise_for_status()
        return response.json()

    async def close(self):
        await self.client.aclose()

    async def __aenter__(self):
        return self

    async def __aexit__(self, exc_type, exc_val, exc_tb):
        await self.close()

# Usage
async def main():
    async with AsyncAPIClient('https://api.example.com', 'your-api-key') as client:
        users = await client.get('/users')
        print(users)
```

## Requirements

```txt
httpx>=0.24.0
# Optional dependencies for additional features:
# httpx-ws>=0.6.0  # WebSocket support
# tqdm>=4.65.0     # Progress bars
# anyio>=3.7.0     # Alternative async runtime
# trio>=0.22.0     # Alternative async runtime
```

## Key Features

- **Sync and Async APIs**: Same interface for both synchronous and asynchronous code
- **HTTP/2 Support**: Full HTTP/2 support with multiplexing
- **Connection Pooling**: Efficient connection management
- **Streaming**: Stream requests and responses without loading everything into memory
- **Authentication**: Built-in support for Basic, Digest, Bearer token, and custom auth
- **Timeouts**: Configurable timeouts for connect, read, and overall requests
- **Redirect Handling**: Configurable redirect following
- **Cookie Handling**: Automatic cookie management
- **Proxy Support**: HTTP and HTTPS proxy support
- **SSL/TLS**: Full SSL/TLS configuration options

## Installation

```bash
uv add httpx

# For HTTP/2 support
uv add httpx[http2]

# For WebSocket support
uv add httpx-ws
```

This skill provides comprehensive HTTP client capabilities for modern Python applications, with excellent async support and production-ready features.

Related Skills

customerio-advanced-troubleshooting

25
from ComeOnOliver/skillshub

Apply Customer.io advanced debugging and incident response. Use when diagnosing complex delivery issues, investigating campaign failures, or running incident playbooks. Trigger: "debug customer.io", "customer.io investigation", "customer.io troubleshoot", "customer.io incident", "customer.io not delivering".

cursor-usage-analytics

25
from ComeOnOliver/skillshub

Track and analyze Cursor usage metrics via admin dashboard: requests, model usage, team productivity, and cost optimization. Triggers on "cursor analytics", "cursor usage", "cursor metrics", "cursor reporting", "cursor dashboard", "cursor ROI".

cursor-upgrade-migration

25
from ComeOnOliver/skillshub

Upgrade Cursor versions, migrate from VS Code, and transfer settings between machines. Triggers on "upgrade cursor", "update cursor", "cursor migration", "cursor new version", "vs code to cursor", "cursor changelog".

cursor-team-setup

25
from ComeOnOliver/skillshub

Set up Cursor for teams: plan selection, member management, shared rules, admin dashboard, and onboarding. Triggers on "cursor team", "cursor organization", "cursor business", "cursor enterprise setup", "cursor admin".

cursor-tab-completion

25
from ComeOnOliver/skillshub

Master Cursor Tab autocomplete, ghost text, and AI code suggestions. Triggers on "cursor completion", "cursor tab", "cursor suggestions", "cursor autocomplete", "cursor ghost text", "cursor copilot".

cursor-sso-integration

25
from ComeOnOliver/skillshub

Configure SAML 2.0 and OIDC SSO for Cursor with Okta, Microsoft Entra ID, and Google Workspace. Triggers on "cursor sso", "cursor saml", "cursor oauth", "enterprise cursor auth", "cursor okta", "cursor entra", "cursor scim".

cursor-rules-config

25
from ComeOnOliver/skillshub

Configure Cursor project rules using .cursor/rules/*.mdc files and legacy .cursorrules. Triggers on "cursorrules", ".cursorrules", "cursor rules", "cursor config", "cursor project settings", ".mdc rules", "project rules".

cursor-reference-architecture

25
from ComeOnOliver/skillshub

Reference architecture for Cursor IDE projects: directory structure, rules organization, indexing strategy, and team configuration patterns. Triggers on "cursor architecture", "cursor project structure", "cursor best practices", "cursor file structure".

cursor-prod-checklist

25
from ComeOnOliver/skillshub

Production readiness checklist for Cursor IDE setup: security, rules, indexing, privacy, and team standards. Triggers on "cursor production", "cursor ready", "cursor checklist", "optimize cursor setup", "cursor onboarding".

cursor-privacy-settings

25
from ComeOnOliver/skillshub

Configure Cursor privacy mode, data handling, telemetry, and sensitive file exclusion. Triggers on "cursor privacy", "cursor data", "cursor security", "privacy mode", "cursor telemetry", "cursor data retention".

cursor-performance-tuning

25
from ComeOnOliver/skillshub

Optimize Cursor IDE performance: reduce memory usage, speed up indexing, tune AI features, and manage extensions for large codebases. Triggers on "cursor performance", "cursor slow", "cursor optimization", "cursor memory", "speed up cursor", "cursor lag".

cursor-multi-repo

25
from ComeOnOliver/skillshub

Work with multiple repositories in Cursor: multi-root workspaces, monorepo patterns, selective indexing, and cross-project context. Triggers on "cursor multi repo", "cursor multiple projects", "cursor monorepo", "cursor workspace", "multi-root workspace".