CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-urllib3

HTTP library with thread-safe connection pooling, file post support, user friendly interface, and more.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

simple-requests.mddocs/

Simple Requests

High-level request interface that provides convenient functions for making HTTP requests without needing to manage connection pools directly. These functions use a module-global PoolManager instance for automatic connection management.

Capabilities

Module-Level Request Function

Makes HTTP requests using a shared global PoolManager instance. This is the simplest way to make HTTP requests with urllib3, suitable for scripts and applications that don't need fine-grained connection management.

def request(method: str, url: str, *, body=None, fields=None, headers=None,
           preload_content=True, decode_content=True, redirect=True,
           retries=None, timeout=3, json=None) -> BaseHTTPResponse:
    """
    A convenience, top-level request method using a module-global PoolManager instance.

    Parameters:
    - method: HTTP request method (GET, POST, PUT, DELETE, etc.)
    - url: The URL to perform the request on
    - body: Data to send in the request body (str, bytes, iterable, or file-like)
    - fields: Data to encode and send in the request body (multipart form data)
    - headers: Dictionary of custom headers to send
    - preload_content: If True, response body will be preloaded into memory
    - decode_content: If True, attempt to decode body based on content-encoding
    - redirect: If True, automatically handle redirects (301, 302, 303, 307, 308)
    - retries: Configure retry behavior (Retry object, int, bool, or None)
    - timeout: Request timeout in seconds (float, int, or Timeout object)
    - json: Data to encode and send as JSON with UTF-8 encoding

    Returns:
    BaseHTTPResponse: Response object with status, headers, and data
    """

Usage Examples

Basic GET Request

import urllib3

# Simple GET request
resp = urllib3.request('GET', 'https://httpbin.org/get')
print(f"Status: {resp.status}")
print(f"Data: {resp.data.decode('utf-8')}")

POST with Form Data

import urllib3

# POST request with form fields
resp = urllib3.request('POST', 'https://httpbin.org/post',
                      fields={'username': 'john', 'password': 'secret'})
print(f"Status: {resp.status}")

POST with JSON Data

import urllib3

# POST request with JSON body
resp = urllib3.request('POST', 'https://httpbin.org/post',
                      json={'message': 'Hello, World!'})
print(f"Status: {resp.status}")

Custom Headers and Timeout

import urllib3

# Request with custom headers and timeout
resp = urllib3.request('GET', 'https://httpbin.org/headers',
                      headers={'User-Agent': 'MyApp/1.0'},
                      timeout=10)
print(f"Status: {resp.status}")

Retry Configuration

import urllib3

# Request with custom retry behavior
retries = urllib3.Retry(total=5, backoff_factor=0.3)
resp = urllib3.request('GET', 'https://httpbin.org/get',
                      retries=retries)

Request Body Types

The body parameter accepts various data types:

  • str: String data (encoded as UTF-8)
  • bytes: Raw byte data
  • Iterable: Iterable of str/bytes for streaming data
  • File-like object: Any object with a read() method

Response Handling

All requests return a BaseHTTPResponse object with:

  • status: HTTP status code (int)
  • headers: Response headers (HTTPHeaderDict)
  • data: Response body as bytes
  • read(): Method to read response data in chunks
  • json(): Method to parse JSON response data

Install with Tessl CLI

npx tessl i tessl/pypi-urllib3

docs

configuration.md

connection-pools.md

exceptions.md

index.md

pool-management.md

response-handling.md

simple-requests.md

utilities.md

tile.json