Skip to main content

Library to convert cURL command line to HTTPie

Project description

Python library to convert cURL command to HTTPie.

It will convert

curl -d name=admin -d shoesize=12 -d color=green&food=wet


http -f name=admin shoesize=12 color=green food=wet


This library was born when I join a project with a team of non-Linux, non-Python developers. Because the project doesn’t have proper documentation, the other team often share API usage example to me in form of cURL command, generated from their daily-used Postman. Those cURL commands are usually ugly, like this:

curl --location --request POST '' \
--header 'Content-Type: application/json' \
--data-raw '{
    "userId": "abc-xyz",
    "planAmount": 50000,
    "isPromotion": false,
    "createdAt": "2019-12-13 10:00:00"

I am more comfortable with HTTPie (shorter syntax, has highlighting and is a Python application), so I often convert it to HTTPie:

http -F userId=abc-xyz planAmount:=50000 isPromotion:=false createdAt='2019-12-13 10:00:00'

The Postman tool can generate HTTPie, but with even uglier command:

printf '{
    "userId": "abc-xyz",
    "planAmount": 50000,
    "isPromotion": false,
    "createdAt": "2019-12-13 10:00:00"
}'| http  --follow --timeout 3600 POST \

Initially, I had to do conversion manually and quickly got tired from it. I tried to find a conversion tool but failed. There is an online tool, but it failed with above example. So I decide to write my own tool.

I don’t bother to help fix the online tool above, because it is written in Go. The rich ecosystem of Python, with these built-in libraries, enable me to finish the job fast:

  • shlex: Help parse the command line in form of shell language, handle the string escaping, quoting for me.
  • argparse: Help parse cURL options and arguments. Note that, cURL arguments syntax follow GNU style, which is common in Linux (and Python) world but not popular in Go world (see this tutorial), so it feels more natural with Python.


>>> from curlipie import curl_to_httpie

>>> curl = """curl -XPUT -d '{"director": "Burton, Tim", "year": 1996, "title": "Mars Attacks!"}' -H 'Content-Type: application/json'"""

>>> curl_to_httpie(curl)
ConversionResult(httpie="http PUT director='Burton, Tim' year:=1996 title='Mars Attacks!'", errors=[])

>>> result = curl_to_httpie(curl)

>>> result.httpie
"http PUT director='Burton, Tim' year:=1996 title='Mars Attacks!'"

Project details

Download files

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

Files for curlipie, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size curlipie-0.2-py3-none-any.whl (6.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size curlipie-0.2.tar.gz (6.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page