Skip to main content

ะฃA command line HTTP client that is easy to use

Project description

Talkie

A convenient command-line HTTP client for interacting with APIs and web services. Talkie makes working with HTTP in the terminal simple and human-friendly thanks to intuitive syntax and beautiful formatted output.

Talkie Logo

License: MIT Python: 3.8+

Contents

Features

  • ๐Ÿš€ Intuitive syntax for working with HTTP requests
  • ๐ŸŒˆ Beautiful colored output with syntax highlighting
  • ๐Ÿ’ก Automatic content type detection (JSON, XML, HTML)
  • ๐Ÿ” OpenAPI specification inspection for convenient API work
  • ๐Ÿ”„ Curl command generation for compatibility
  • ๐Ÿ“ Automatic data formatting (JSON, XML, HTML, Markdown)
  • ๐ŸŒ Environment support for working with different APIs
  • ๐Ÿ” Save and reuse headers and tokens
  • ๐Ÿ’พ Save responses to files
  • ๐Ÿงฐ Full support for all HTTP methods
  • ๐ŸŒ WebSocket connections for bidirectional communication
  • ๐Ÿ“Š GraphQL requests for working with GraphQL APIs
  • ๐Ÿ“œ Request history for reuse and analysis
  • โšก Parallel request execution for improved performance

Installation

From PyPI

pip install talkie

From source code

git clone https://github.com/craxti/talkie.git
cd talkie
pip install -e .

Usage

Basic Requests

# GET request
talkie get https://api.example.com/users

# POST request with JSON data (automatic type detection)
talkie post https://api.example.com/users name=John age:=30 is_admin:=true

# PUT request
talkie put https://api.example.com/users/1 name=Peter

# DELETE request
talkie delete https://api.example.com/users/1

Headers and Parameters

# Adding headers
talkie get https://api.example.com/users \
  -H "Authorization: Bearer token123" \
  -H "Accept: application/json"

# Query parameters
talkie get https://api.example.com/users -q "page=1" -q "limit=10"

# Save response to file
talkie get https://api.example.com/users -o users.json

Output and Formatting

# Verbose output
talkie get https://api.example.com/users -v

# JSON only
talkie get https://api.example.com/users --json

# Headers only
talkie get https://api.example.com/users --headers

# Response formatting
talkie get https://api.example.com/users --format json
talkie get https://api.example.com/users -f xml

Curl Command Generation

# Generate curl command for request
talkie curl https://api.example.com/users -H "Authorization: Bearer token123"

# Add curl command to regular request
talkie get https://api.example.com/users --curl

# Configure curl parameters
talkie curl https://api.example.com/users -X POST -d "name=John" -d "age:=30" -v -k

OpenAPI Inspection

# Inspect OpenAPI specification from URL
talkie openapi https://api.example.com/openapi.json

# Inspect local specification file
talkie openapi ./openapi.yaml

# Show only endpoints
talkie openapi https://api.example.com/openapi.json --endpoints

# Generate request examples
talkie openapi https://api.example.com/openapi.json --examples

File Formatting

# Format JSON file
talkie format data.json

# Format and save to file
talkie format data.json -o formatted.json

# Format with specific type
talkie format data.txt -t json

WebSocket

# Connect to WebSocket server
talkie ws wss://echo.websocket.org

# Send message
talkie ws wss://echo.websocket.org --send "Hello"

# Connect with headers
talkie ws wss://api.example.com/ws \
  -H "Authorization: Bearer token123"

GraphQL Requests

# Simple query
talkie graphql https://api.example.com/graphql \
  -q "query { users { id name } }"

# Query from file
talkie graphql https://api.example.com/graphql -f query.graphql

# Query with variables
talkie graphql https://api.example.com/graphql \
  -f query.graphql -v id=123 -v limit=10

Request History

# Show history
talkie history list

# Show last 10 requests
talkie history list --limit 10

# Search history
talkie history search --method GET --url users

# Repeat request from history
talkie history repeat 1a2b3c4d

# Search in history
talkie history search --method GET --url users

# Export history to file
talkie history export history.json

# Import history from file
talkie history import history.json

Parallel Request Execution

# Execute requests from file
talkie parallel -f requests.txt

# File with requests (requests.txt) has format:
# GET https://api.example.com/users/1
# GET https://api.example.com/users/2
# POST https://api.example.com/users name=John

# Execute multiple requests with parallelism limit
talkie parallel -f requests.txt --concurrency 5

# Use delay between requests
talkie parallel -f requests.txt --delay 0.5

# Save results to separate files
talkie parallel -f requests.txt --output-dir ./results

# Execute multiple requests to one URL
talkie parallel -X GET -u "/users/1" -u "/users/2" -u "/posts/1" -b "https://api.example.com"

Configuration Management

Configuration File

Talkie uses ~/.talkie/config.json file for storing settings. The file is created automatically on first run.

You can create the file manually:

mkdir -p ~/.talkie
cat > ~/.talkie/config.json << EOF
{
  "default_headers": {
    "User-Agent": "Talkie/0.1.0",
    "Accept": "application/json"
  },
  "environments": {
    "dev": {
      "name": "dev",
      "base_url": "https://dev-api.example.com",
      "default_headers": {
        "Authorization": "Bearer dev-token"
      }
    },
    "prod": {
      "name": "prod",
      "base_url": "https://prod-api.example.com",
      "default_headers": {
        "Authorization": "Bearer prod-token"
      }
    }
  },
  "active_environment": "dev"
}
EOF

Configuration file location can be changed using TALKIE_CONFIG_DIR environment variable.

Environment Management

Environments allow storing settings for different APIs and quickly switching between them.

Example of using environment:

# Using base URL from active environment
talkie get /users

# Equivalent to (if active environment is dev)
talkie get https://dev-api.example.com/users

Configuration Examples

Multiple Headers for All Requests

{
  "default_headers": {
    "User-Agent": "Talkie/0.1.0",
    "Accept": "application/json",
    "X-API-Key": "your-api-key"
  }
}

Multiple Environment Setup

{
  "environments": {
    "github": {
      "name": "github",
      "base_url": "https://api.github.com",
      "default_headers": {
        "Authorization": "token ghp_xxxxxxxxxxxx"
      }
    },
    "gitlab": {
      "name": "gitlab",
      "base_url": "https://gitlab.com/api/v4",
      "default_headers": {
        "PRIVATE-TOKEN": "glpat-xxxxxxxxxxxx"
      }
    }
  },
  "active_environment": "github"
}

Development

Requirements

  • Python 3.8+
  • httpx
  • typer
  • rich
  • pydantic
  • pyyaml
  • openapi-spec-validator
  • pygments
  • xmltodict
  • html2text
  • websockets

Project Structure

talkie/
โ”œโ”€โ”€ __init__.py          # Package
โ”œโ”€โ”€ __main__.py          # Entry point
โ”œโ”€โ”€ cli/                 # Command line interface
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ main.py          # Command definitions
โ”œโ”€โ”€ core/                # Application core
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ client.py        # HTTP client
โ”‚   โ”œโ”€โ”€ request_builder.py
โ”‚   โ”œโ”€โ”€ response_formatter.py
โ”‚   โ””โ”€โ”€ websocket_client.py  # WebSocket client
โ””โ”€โ”€ utils/               # Helper modules
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ config.py        # Configuration management
    โ”œโ”€โ”€ formatter.py     # Data formatting
    โ”œโ”€โ”€ curl_generator.py
    โ”œโ”€โ”€ openapi.py
    โ”œโ”€โ”€ graphql.py       # GraphQL support
    โ”œโ”€โ”€ history.py       # Request history
    โ”œโ”€โ”€ colors.py
    โ””โ”€โ”€ logger.py

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run all tests
pytest

# Run tests for specific module
pytest tests/test_formatter.py

# Run integration tests
pytest tests/test_integration.py

# Check code coverage
pytest --cov=talkie

API Documentation

API documentation is available in docs/api_reference.md.

It contains detailed description of all Talkie API components:

  • HTTP client and request builder
  • WebSocket client
  • Utilities for formatting and working with various formats
  • GraphQL request interface
  • Components for storing and managing request history

FAQ

How to save response to file?

Use -o or --output option:

talkie get https://api.example.com/data -o response.json

How to use OAuth token?

Add Authorization header:

talkie get https://api.example.com/profile -H "Authorization: Bearer YOUR_TOKEN"

Or save it in configuration:

{
  "environments": {
    "myapi": {
      "base_url": "https://api.example.com",
      "default_headers": {
        "Authorization": "Bearer YOUR_TOKEN"
      }
    }
  },
  "active_environment": "myapi"
}

How to work with WebSocket in async scenarios?

Talkie provides Python API for working with WebSocket:

import asyncio
from talkie.core.websocket_client import WebSocketClient

async def main():
    client = WebSocketClient("wss://echo.websocket.org")
    await client.connect()
    await client.send("Hello")
    response = await client.receive()
    print(f"Received: {response.data}")
    await client.disconnect()

asyncio.run(main())

How to execute complex GraphQL query?

Save query to file and pass it to command:

talkie graphql https://api.example.com/graphql -f complex_query.graphql -v id=123 -v limit=10

License

MIT

Contributing

Contributions are welcome! Please create issues and pull requests on GitHub.

  1. Fork the repository
  2. Create a branch with your changes
  3. Submit a pull request

Code guidelines:

  • Use black for code formatting
  • Add type hints
  • Write tests for new functionality

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

talkie-0.1.1.tar.gz (65.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

talkie-0.1.1-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file talkie-0.1.1.tar.gz.

File metadata

  • Download URL: talkie-0.1.1.tar.gz
  • Upload date:
  • Size: 65.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for talkie-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4e63e25d6dd7f20cf475c6025031b5a1201386efe9d3f0ad325ec53a3d8e3162
MD5 0114ddaa93646e9876ea550ddb9f379f
BLAKE2b-256 4746a572622f7f2b18c69c238add76659f052a950d3fdac601c7c53577fd6be6

See more details on using hashes here.

File details

Details for the file talkie-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: talkie-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for talkie-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f1362bbf53988cdebba528322237fc119308d25e59ea0ea14e40f22d62ac064
MD5 35afe771864ac7a26fec471251c0c73a
BLAKE2b-256 81ea4ba9b72165017f2de6c33f678be3fb207bc09d3c702c8c05ecd273213028

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page