Skip to main content

CurliPie

https://madewithlove.open-api.vn/vn?heart=true&colorA=%23ffcd00&colorB=%23da251d https://badgen.net/pypi/v/curlipie

Python library to convert cURL command to HTTPie.

It will convert

curl -d name=admin -d shoesize=12 -d color=green&food=wet http://quan.hoabinh.vn

to

http -f http://quan.hoabinh.vn name=admin shoesize=12 color=green food=wet

Motivation

This library was born when I joined a project with a team of non-Linux, non-Python developers. Because the project didn’t have proper documentation, the other team often shared 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 'http://app-staging.dev/api' \
--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 converted it to HTTPie:

http -F app-staging.dev/api userId=abc-xyz planAmount:=50000 isPromotion:=false createdAt='2019-12-13 10:00:00'

Though Postman can generate HTTPie, it does result in even uglier command:

printf '{
    "userId": "abc-xyz",
    "planAmount": 50000,
    "isPromotion": false,
    "createdAt": "2019-12-13 10:00:00"
}'| http  --follow --timeout 3600 POST app-staging.dev/api \
Content-Type:'application/json'

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 curl2httpie.online, 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.

Usage

>>> from curlipie import curl_to_httpie

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

>>> curl_to_httpie(curl)
ConversionResult(httpie="http PUT elastic.dev/movies/_doc/1 director='Burton, Tim' year:=1996 title='Mars Attacks!'", errors=[])

>>> result = curl_to_httpie(curl)

>>> result.httpie
"http PUT elastic.dev/movies/_doc/1 director='Burton, Tim' year:=1996 title='Mars Attacks!'"

Online tool

CurliPie is not very usable if it stays in library form, so I made an online tool for you to use it quickly:

https://curlipie.open-api.vn

The site also provide HTTP API for you to develop a client for it.

Development

This repo contains three components:

To try running on localhost:

  • Run backend with:

    uvicorn api.main:app
  • The front-end are just static files, served by backend also, so you can access it via http://localhost:8000/. The CSS is generated depending on which CSS classes are used. To generate CSS file, install Bun, then run the command:

    ./tools/generate-css.sh

Unit test:

pytest

Credit

Brought to you by Nguyễn Hồng Quân.

Metadata

Release files for curlipie 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curlipie 0.9.0
File Size Uploaded
curlipie-0.9.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for curlipie 0.9.0
File Interpreter ABI Platform
curlipie-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / curlipie-0.9.0.tar.gz

Download URL curlipie-0.9.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e6a7dae9d82320be9306e4fc4b939d3018ca8b4c916bb702f81d3a032fc1c8ef
BLAKE2b-256 checksum
How to use checksums
a3099c8e4f82a155ec3f903e0f7a208919f89fb2135225b52d8a78def46470e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.6 Linux/6.5.0-35-generic

Release files / curlipie-0.9.0-py3-none-any.whl

Download URL curlipie-0.9.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2dc76071ba3da13ac191769354d4a3ac08ddc45c4bd3f16dbf3d45d83484369a
BLAKE2b-256 checksum
How to use checksums
83dc41281ef9ea663cafb6110354bc265449566a79a316534cdb839ac4693b4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.6 Linux/6.5.0-35-generic

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page