Convert curl commands to Python requests code
Project description
curl-converter
Convert curl commands into Python requests code.
Installation
pip install curl2python
Example Usage
from curl2python import curl_to_python
curl_text = """
curl 'https://books.toscrape.com/' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cache-control: no-cache' \
-H 'pragma: no-cache' \
-H 'priority: u=0, i' \
-H 'referer: https://www.google.com/' \
-H 'sec-ch-ua: "Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'sec-fetch-dest: document' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-site: cross-site' \
-H 'sec-fetch-user: ?1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36'
"""
data = curl_to_python(curl_text)
print(data)
Output
{
'method': 'GET',
'url': 'https://books.toscrape.com/',
'headers': {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'no-cache',
'pragma': 'no-cache',
'priority': 'u=0, i',
'referer': 'https://www.google.com/',
'sec-ch-ua': '"Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'cross-site',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36'
},
'cookies': None,
'params': None,
'data': None,
'json': None,
'files': None
}
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
curl2python-0.1.4.tar.gz
(3.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file curl2python-0.1.4.tar.gz.
File metadata
- Download URL: curl2python-0.1.4.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52a582c8043195d5089edf772256673b8034c6fb46fa4f31b665b365d032b58b
|
|
| MD5 |
fad3193fa5aa5a70a5d08576c6f554fa
|
|
| BLAKE2b-256 |
240e86896153cfef3cdffa60f48fdaaa9d446b68e1112db6e4cb37cdb7f93f9b
|
File details
Details for the file curl2python-0.1.4-py3-none-any.whl.
File metadata
- Download URL: curl2python-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cca1bd555789e8030a60dfbfc48a1dbc513ad106b6f5d21a517a54dd7e79842
|
|
| MD5 |
ccb89818426951ab161daa2f3745c57f
|
|
| BLAKE2b-256 |
b8d311e68fc191ad7f263be7b0a39257f4690ae07a35d51ca12f873b6b8d6c5c
|