cURL to Python Requests Converter

Convert raw cURL CLI commands into idiomatic Python requests script snippets.

  • 100% free
  • Private in browser
  • No signup
  • No watermarks

Python Requests Code (POST https://api.example.com/v1/items)

import requests

url = "https://api.example.com/v1/items"
headers = {
    "Authorization": "Bearer token123",
    "Content-Type": "application/json",
}
payload = {
    "item": "book",
    "qty": 2
}

response = requests.post(url, headers=headers, json=payload)
print("Status:", response.status_code)
print("Response:", response.text)

About cURL to Python Requests Converter

The cURL to Python Requests Converter turns a cURL command into a short Python script that uses the requests library. Paste a command copied from API docs or your browser DevTools, and the tool reads the URL, the HTTP method, each -H header, and the -d request body, then writes the matching requests call with a headers dictionary. It is a quick way to move an API call from the terminal into a Python script. The command is parsed in your browser, so tokens in your headers are never uploaded.

How to use cURL to Python Requests Converter

  1. Copy a cURL command from your API docs, terminal, or browser DevTools.
  2. Paste it into the Input cURL Command box.
  3. Check the generated URL, method, headers, and request body.
  4. Click Copy Python and run the code in your script.

Key features

  • Reads the request URL and the method from -X or --request
  • Turns every -H or --header into a Python headers dictionary
  • Reads the request body from -d, --data, or --data-raw
  • Switches to POST automatically when a body is present
  • Prints the response status code and text
  • Runs in your browser — commands and tokens are never uploaded

Frequently asked questions

How do I convert a cURL command to Python requests?
Paste the cURL command into the input box and the tool generates the equivalent Python requests code instantly. Click Copy Python to copy it into your script.
Which cURL options does the converter support?
It supports the URL, -X or --request for the method, -H or --header for headers, and -d, --data, or --data-raw for the body. Other options, such as -u, -F, and -b, are ignored, so add those to the code by hand.
Does it send the body as JSON or form data?
If the command has a Content-Type: application/json header, the body is passed with json=payload. Otherwise it is passed with data=payload.
Do I need to review the generated code?
Yes. Always check the request body before you run the code, especially for JSON bodies with nested quotes. JSON true, false, and null must be written as True, False, and None in Python.
Is it safe to paste a cURL command with an API key?
The command is parsed locally in your browser and is not sent to a server. It is still good practice to replace real tokens with placeholders before sharing the generated code.

Rate this tool

Be the first to rate — helps others and improves this page.