cURL to Python Requests Converter

Paste a literal cURL command to get Python requests code with its method, URL, headers and body. The converter only turns text into code and never sends the request. Everything runs in your browser and your input stays on this device.

What this tool does

Translate supported literal cURL arguments into a Python requests snippet without executing it.

Conversion doesn’t send the request

This tool translates the command into Python code and does not execute anything. A request is made only when you run the generated Python yourself, so review the URL, headers and any credentials first.

When to use it

Use a representative HTTP request as a starting point when moving a terminal fixture into an integration test.

How to use it

  1. Paste a literal cURL command with synthetic values.
  2. Select Convert to Python.
  3. Review method, URL, timeout, headers, body and redirects before running the snippet in your environment.

To check a JSON request body first, use the JSON Formatter.

Worked example

Load the example request to example.com and convert it. Review the generated requests call. The URL, Accept header and JSON body should all be visible. When porting a browser request, start from a small request you can understand and remove sensitive headers and cookies before using an example in documentation. Inspect the generated timeout and any redirect option before running it in your own Python environment. Conversion is a text operation. Running the generated Python sends a real request to the address in the code.

Example input
curl 'https://example.com/api/items' -H 'Accept: application/json'
Example output
import requests

response = requests.request(
    "GET",
    "https://example.com/api/items",
    headers={"Accept":"application/json"},
    allow_redirects=False,
    timeout=30,
)
print(response.status_code)
print(response.text)

Supported features and limitations

Supports one HTTP URL, headers, literal data, basic auth, cookies and redirects. Shell expansions, files, multipart forms and unsupported flags produce errors. Review any credentials before sharing the output.

Common mistakes and edge cases

The converter accepts literal arguments. Variables such as $TOKEN, substitutions that call other programs and arguments that load a local file depend on the shell or filesystem. Replace them with harmless test literals when building an example, then wire environment variables or file reads into your Python code explicitly. Multipart uploads and unsupported cURL options need a hand-written requests call. Make sure the generated request retains the content type your endpoint expects. For a request you plan to keep as a fixture, replace private hostnames and credentials with demonstration values before committing it. If the service expects raw bytes, compare the original request body with the body the Python client sends.

Frequently asked questions

Can I use a command copied from a browser?
Use the browser option that exports cURL with POSIX-style quoting. Check for cookies, authorization headers and other sensitive values before sharing either the command or its Python output.
What should I verify before running the generated snippet?
Check the target URL, method, headers, body, redirect behavior and timeout. Read the response and handle errors in your application before relying on the snippet in a recurring job.
Does this send my request?
No. Conversion is a text operation. The request is sent only if you run the generated Python code.
Which cURL options are supported?
One HTTP(S) URL, headers, literal request data, basic authentication, cookies and redirects. Shell variables, substitutions, local files, multipart forms and unsupported flags produce errors.
Why does my command fail to convert?
The converter accepts literal arguments only. Replace variables such as $TOKEN and command substitutions with test values, and write multipart uploads or file reads by hand in your Python code.
Is my cURL command uploaded anywhere?
No. It is processed in your browser and stays on your device.
Why does the generated code set allow_redirects to False?
cURL does not follow redirects unless you pass -L or --location, so the generated code mirrors that. Add -L to your command if you want redirects followed.

Related tools

Developer guides