or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdclient.mdconfiguration.mdindex.mdmodels.mdplugins.mdsessions.mdutilities.md
tile.json

tessl/pypi-httpie

HTTPie: modern, user-friendly command-line HTTP client for the API era.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/httpie@3.2.x

To install, run

npx @tessl/cli install tessl/pypi-httpie@3.2.0

index.mddocs/

HTTPie

HTTPie is a modern, user-friendly command-line HTTP client designed for the API era. It provides an intuitive syntax for creating and sending arbitrary HTTP requests with formatted and colorized output, making it ideal for testing, debugging, and interacting with APIs and HTTP servers.

Package Information

  • Package Name: httpie
  • Package Type: pypi
  • Language: Python
  • Installation: pip install httpie

Core Imports

For programmatic usage:

import httpie
from httpie.core import main, raw_main, program, collect_messages
from httpie.context import Environment
from httpie.status import ExitStatus
from httpie.models import RequestsMessage
from httpie.sessions import get_httpie_session, Session
from httpie.config import Config

Plugin development:

from httpie.plugins import AuthPlugin, FormatterPlugin, ConverterPlugin, TransportPlugin
from httpie.plugins.base import BasePlugin

Basic Usage

Command Line Interface

HTTPie provides three main command-line utilities:

# Basic GET request
http httpie.io/hello

# Custom HTTP method with headers and JSON data
http PUT pie.dev/put X-API-Token:123 name=John

# POST with form data
http --form POST pie.dev/post name=John email=john@example.com

# Download a file
http --download https://example.com/file.zip

# Authentication
http -a username:password httpie.io/basic-auth/username/password

# Sessions (preserve cookies and auth)
http --session=logged-in -a username:password pie.dev/basic-auth/username/password
http --session=logged-in pie.dev/cookies

Programmatic Usage

import sys
from httpie.core import main
from httpie.context import Environment

# Create environment
env = Environment()

# Make HTTP request programmatically
exit_status = main(['http', 'httpie.io/hello'], env)

if exit_status == 0:
    print("Request successful")
else:
    print(f"Request failed with status: {exit_status}")

Architecture

HTTPie follows a modular architecture with several key components:

  • Core Engine: Main request processing and argument parsing (httpie.core)
  • CLI Interface: Command-line argument definition and parsing (httpie.cli)
  • HTTP Client: Request/response handling built on Python requests (httpie.client)
  • Output System: Formatting and display of HTTP messages (httpie.output)
  • Plugin System: Extensible architecture for auth, formatting, and transport (httpie.plugins)
  • Session Management: Persistent session storage and retrieval (httpie.sessions)
  • Manager Interface: HTTPie package and plugin management (httpie.manager)

Capabilities

Command-Line HTTP Client

The primary interface providing http, https, and httpie commands for making HTTP requests with human-friendly syntax, automatic JSON support, and rich output formatting.

def main(args: List[Union[str, bytes]] = sys.argv, env: Environment = Environment()) -> ExitStatus:
    """Main HTTPie function that processes command-line arguments and executes HTTP requests."""

def raw_main(parser: argparse.ArgumentParser, main_program: Callable[[argparse.Namespace, Environment], ExitStatus], args: List[Union[str, bytes]] = sys.argv, env: Environment = Environment(), use_default_options: bool = True) -> ExitStatus:
    """Core main function with error handling and plugin loading."""

def program(args: argparse.Namespace, env: Environment) -> ExitStatus:
    """The main program without error handling."""

def collect_messages(env: Environment, args: argparse.Namespace, request_body_read_callback: Callable[[bytes], None] = None) -> Iterable[RequestsMessage]:
    """Core message collection and HTTP execution."""

Command-Line Interface

HTTP Client

Low-level HTTP client functions for building and sending requests programmatically, including message collection, session building, and request preparation utilities.

def build_requests_session(session_name: str = None, config_dir: str = None, read_only: bool = False, **session_kwargs) -> requests.Session:
    """Build a requests session with HTTPie configurations."""

def make_request_kwargs(args: argparse.Namespace, base_headers: dict = None) -> dict:
    """Build keyword arguments for requests.request()."""

def make_send_kwargs(args: argparse.Namespace) -> dict:
    """Build keyword arguments for session.send()."""

HTTP Client

Plugin Development

Extensible plugin system supporting authentication, output formatting, content conversion, and custom transport adapters.

class AuthPlugin(BasePlugin):
    auth_type: str
    def get_auth(self, username: str = None, password: str = None): ...

class FormatterPlugin(BasePlugin):
    def format_headers(self, headers: str) -> str: ...
    def format_body(self, content: str, mime: str) -> str: ...

class ConverterPlugin(BasePlugin):
    def convert(self, body: bytes) -> Tuple[str, str]: ...

class TransportPlugin(BasePlugin):
    prefix: str
    def get_adapter(self): ...

Plugin Development

Session Management

Persistent session storage for maintaining cookies, authentication, and custom request settings across multiple HTTP requests.

class Session:
    def load(self) -> Dict[str, Any]: ...
    def save(self) -> None: ...
    def delete(self) -> None: ...

def get_httpie_session(env: Environment, config_dir: Path, session_name: str, host: Optional[str], url: str, *, suppress_legacy_warnings: bool = False) -> Session:
    """Get or create a HTTPie session for persistent data storage."""

Session Management

Configuration Management

Configuration system for managing HTTPie settings, default options, and plugin directories.

class Config:
    default_options: List[str]
    plugins_dir: str
    
def get_default_config_dir() -> str:
    """Get the default HTTPie configuration directory."""

Configuration

HTTP Models and Status

Data models for HTTP requests/responses and comprehensive exit status codes for different scenarios.

class ExitStatus(IntEnum):
    SUCCESS = 0
    ERROR = 1
    ERROR_TIMEOUT = 2
    ERROR_HTTP_3XX = 3
    ERROR_HTTP_4XX = 4
    ERROR_HTTP_5XX = 5
    ERROR_TOO_MANY_REDIRECTS = 6
    PLUGIN_ERROR = 7
    ERROR_CTRL_C = 130

def http_status_to_exit_status(http_status: int, follow: bool = False) -> ExitStatus:
    """Convert HTTP status code to HTTPie exit status."""

HTTP Models

Constants and Utilities

HTTP processing constants, utility functions, and helper classes for request parsing, output formatting, and data handling.

# HTTP method constants
HTTP_GET: str = 'GET'
HTTP_POST: str = 'POST'
HTTP_OPTIONS: str = 'OPTIONS'

# Output option constants
OUT_REQ_HEAD: str = 'H'
OUT_REQ_BODY: str = 'B'  
OUT_RESP_HEAD: str = 'h'
OUT_RESP_BODY: str = 'b'
OUT_RESP_META: str = 'm'

# Utility functions
def humanize_bytes(n: int, precision: int = 2) -> str: ...
def get_content_type(filename: str) -> str: ...
def split_cookies(cookie_header: str) -> List[str]: ...

Constants and Utilities

Types

from typing import List, Union, Optional, Callable, Iterable, Dict, Any, IO, Tuple
from pathlib import Path
import argparse

class Environment:
    """HTTPie execution environment containing stdin/stdout/stderr and configuration."""
    program_name: str
    stdin_encoding: str
    is_windows: bool
    config: Config
    stdin: IO
    stdout: IO
    stderr: IO

class RequestsMessage:
    """HTTP request or response message wrapper."""
    
class OutputOptions:
    """Configuration for what parts of HTTP messages to output."""
    
class ProcessingOptions:
    """Configuration for how to process and format output."""

class Config:
    """HTTPie configuration management."""
    default_options: List[str]
    plugins_dir: Path

class Session:
    """HTTPie session for persistent request data."""
    def load(self) -> Dict[str, Any]: ...
    def save(self) -> None: ...
    def delete(self) -> None: ...