Skip to content

imtoopunkforyou/curlifier

Repository files navigation

Poetry codecov tests pypi package version status pypi downloads supported python versions wemake-python-styleguide mypy ruff license

Curlifier logo

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

Security

The resulting curl command will include all authentication credentials, API keys, passwords, and other sensitive information that were part of the original request. Be careful when sharing or logging these commands, as they may expose sensitive data.

Installation

pip install curlifier

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 PreparedRequest, 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.

The logo was created using Font Meme.

About

Converts Request objects to curl string

Resources

Contributing

Stars

Watchers

Forks