Skip to main content

Converts Request objects to curl string

Project description

curlifier

coverage pypi package version pypi downloads supported python versions wemake-python-styleguide

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

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

Installation

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 '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 '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, insecure=True)
curl --request POST 'https://httpbin.org/' <...> --header 'Content-Type: application/json' --data '{"id": 1, "name": "Tima", "age": 28}' --location --insecure
  • 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.

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.7.tar.gz (8.1 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.7-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: curlifier-0.1.7.tar.gz
  • Upload date:
  • Size: 8.1 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.7.tar.gz
Algorithm Hash digest
SHA256 cd7c18e5cd951d460329d63f8366d151187d556a963b9ce7a00ce19e571b54e0
MD5 a73a281d3246c3f91d933464a7df5f8c
BLAKE2b-256 e762dcf7122a824446f168e189642d2045f0e19b233756a2383563c62d587d36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: curlifier-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 260ba7cee3450c9d329902e3236be72d06fe2027a18f7b064f61d040bab5b21b
MD5 4001004bd47fa9e92ae466f8b68189df
BLAKE2b-256 bbf16b6593021840fd7c334bec286abeb2a4d0faf863b9a23a3581555b484150

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