Convert curl commands to Python HTTP client code
Project description
curlformat
A Python package to convert curl commands to Python HTTP client code.
Features
- Convert curl commands to Python code for various HTTP libraries:
- requests (default)
- httpx (with sync and async support)
- aiohttp
- pycurl
- pyhttpx
- curl_cffi (with sync and async support)
- Parse curl commands from command line, clipboard, or stdin
- Support for headers, cookies, data, and more
Installation
pip install curlformat
Usage
Command Line
# Basic usage (converts to requests)
curlformat 'curl -X GET "https://api.example.com"'
# Convert to httpx
curlformat --httpx 'curl -X GET "https://api.example.com"'
# Convert to async httpx
curlformat --httpx --async 'curl -X GET "https://api.example.com"'
# Convert to aiohttp
curlformat --aiohttp 'curl -X GET "https://api.example.com"'
# Read from clipboard if no curl command is provided
curlformat --httpx
# Read from stdin
cat curl_command.txt | curlformat --pycurl
Python API
from curlformat import parse
# Convert curl command to requests code
python_code = parse('curl -X GET "https://api.example.com"')
print(python_code)
# If httpx is installed
from curlformat import parse_httpx, parse_httpx_async
# Convert to httpx code
httpx_code = parse_httpx('curl -X GET "https://api.example.com"')
print(httpx_code)
# Convert to async httpx code
httpx_async_code = parse_httpx_async('curl -X GET "https://api.example.com"')
print(httpx_async_code)
Optional Dependencies
The package has the following optional dependencies:
httpx: For httpx supportaiohttp: For aiohttp supportpycurl: For pycurl supportpyhttpx: For pyhttpx supportcurl_cffi: For curl_cffi support
You can install all optional dependencies with:
pip install curlformat[all]
Or install specific dependencies:
pip install curlformat[httpx,aiohttp]
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
curlformat-0.1.2.tar.gz
(15.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file curlformat-0.1.2.tar.gz.
File metadata
- Download URL: curlformat-0.1.2.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c22ff4ad75be23f7559212181d3f79bb86f8a6c43edd6d64fbcc5a720b05a977
|
|
| MD5 |
3d0aca9c10a56c1e1cce246b890923a6
|
|
| BLAKE2b-256 |
b37aea09822176e48d7214581e50cc7404ee5f1e7d2439ae111a1169f99cd672
|
File details
Details for the file curlformat-0.1.2-py3-none-any.whl.
File metadata
- Download URL: curlformat-0.1.2-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
307cfa6158d891c75398f7cec46456a279fc4e322980f65de838957f6e136d6a
|
|
| MD5 |
139a713d1dfda28d73b72cd6912cde50
|
|
| BLAKE2b-256 |
0d8bd638e8e33cabad2ad4c616a0bd5587d1a44ca0950c899244d0b2036cd2df
|