Skip to main content

Converts Request objects to curl string

Project description

curlifier

░█████╗░██╗░░░██╗██████╗░██╗░░░░░██╗███████╗██╗███████╗██████╗░
██╔══██╗██║░░░██║██╔══██╗██║░░░░░██║██╔════╝██║██╔════╝██╔══██╗
██║░░╚═╝██║░░░██║██████╔╝██║░░░░░██║█████╗░░██║█████╗░░██████╔╝
██║░░██╗██║░░░██║██╔══██╗██║░░░░░██║██╔══╝░░██║██╔══╝░░██╔══██╗
╚█████╔╝╚██████╔╝██║░░██║███████╗██║██║░░░░░██║███████╗██║░░██║
░╚════╝░░╚═════╝░╚═╝░░╚═╝╚══════╝╚═╝╚═╝░░░░░╚═╝╚══════╝╚═╝░░╚═╝

Curlifier converts the Request and PreparedRequest objects of the Requests library into an executable curl command.

Installation

Curlifier is available on PyPI:

pip install curlifier

Dependencies

  • python (>=3.12, <4.0)
  • requests (>=2.30.3, <3.0.0)

Usage

All you need is to import curlify.
For example:

>>> import requests
>>> from curlifier import curlify
>>> body = {'id': 1, 'name': 'Tima', 'age': 28}
>>> r = requests.post('https://httpbin.org/', json=body)
>>> curlify(r)
curl --request POST 'https://httpbin.org/' --header 'User-Agent: python-requests/2.32.3' --header 'Accept-Encoding: gzip, deflate' --header 'Accept: */*' --header 'Connection: keep-alive' --header 'Content-Type: application/json' --data '{"id": 1, "name": "Tima", "age": 28}'

If you use PraparedRequest, you can also specify it instead of the Response object:

>>> req = requests.Request('POST', 'https://httpbin.org/')
>>> r = req.prepare()
>>> curlify(prepared_request=r)
curl --request POST 'https://httpbin.org/'

If you want a short version of the curl command, you can specify it:

>>> body = {'id': 1, 'name': 'Tima', 'age': 28}
>>> r = requests.post('https://httpbin.org/', json=body)
>>> curlify(r, shorted=True)
curl -X POST 'https://httpbin.org/' -H 'User-Agent: python-requests/2.32.3' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -d '{"id": 1, "name": "Tima", "age": 28}'

You can also specify the configuration when forming the curl command:

>>> curlify(r, location=True, verbose=True, silent=True, insecure=True, include=True)
curl --request POST 'https://httpbin.org/' --header 'User-Agent: python-requests/2.32.3' --header 'Accept-Encoding: gzip, deflate' --header 'Accept: */*' --header 'Connection: keep-alive' --header 'Content-Type: application/json' --data '{"id": 1, "name": "Tima", "age": 28}' --location --verbose --silent --insecure --include
  • location (bool) - Follow redirects (default: False)
  • verbose (bool) - Verbose output (default: False)
  • silent (bool) - Silent mode (default: False)
  • insecure (bool) - Allow insecure connections (default: False)
  • include (bool) - Include protocol headers (default: False)

License

Curlifier is released under the MIT License. See the bundled LICENSE file for details.

Want to Help? ❤️

Feel free to pick any task from this list and contribute!

  1. Check if an issue exists for the task you want to work on
  2. If not, open a new issue to discuss
  3. Fork the repo and create a pull request when ready

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

curlifier-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

curlifier-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file curlifier-0.1.0.tar.gz.

File metadata

  • Download URL: curlifier-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for curlifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d395b661cce84e5b78f680f8c6fd8f800c315e995635a8131166cc1132da1e49
MD5 3a91d76a770241809010a4aae934bf19
BLAKE2b-256 219b22745989350ed36a58dcccf228f39566be6e73755c362c7f9e1fbab5c7f4

See more details on using hashes here.

File details

Details for the file curlifier-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: curlifier-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for curlifier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a67a4e13227dafbcb75ac6b4894000e4fdb2e7555603641f623ffa1a0b9a720
MD5 781a8193c14b197da324a63add129d27
BLAKE2b-256 d4e501751a10e9bef5c868a0a9ddb105566ef78c4d28f748e7eade0e27ab519c

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