# Curl to Python requests: every common flag and its requests argument

> A lookup table for headers, bodies, auth, uploads and redirects, plus the cleanups a converted script needs.

URL: https://claudegpt.si/news/curl-to-python-requests-flag-mapping  
Published: 2026-10-27T15:08:43.585Z  
Author: ClaudeGPT Si Newsroom  
Section: Guides  
Topics: Python requests, Curl, API monitoring  
Publisher: ClaudeGPT Si

## Key takeaways

- Each curl flag maps to a requests argument: -H to headers, -d to data, -u to auth, -F to files and -b to cookies.
- The free AyeTab cURL converter drafts the requests code from the URL, method, headers and body, in your browser.
- After converting, move tokens into environment variables, use json= for JSON bodies and always set a timeout.

Every curl flag has a matching argument in Python's requests library, so curl to Python requests is mostly a lookup: the URL becomes the first argument, `-H` becomes `headers`, `-d` becomes `data`, and `-X` picks the function. The quickest way to do the lookup is to let the free [AyeTab cURL converter](https://app.ayetab.com/tools/curl-code) write the first draft, then adjust the rest by hand with the table below.

## The mapping, flag by flag

| curl | requests | Note |
| --- | --- | --- |
| `curl URL` | `requests.get(URL)` | GET is the default in both |
| `-X POST` | `requests.post(...)` | Same for put, patch, delete |
| `-H "Key: value"` | `headers={"Key": "value"}` | One dict entry per header |
| `-d 'a=1&b=2'` | `data=...` | Sent as the request body |
| `--json '{...}'` | `json={...}` | Pass a dict and requests encodes it |
| `-u user:pass` | `auth=("user", "pass")` | Basic auth |
| `-F file=@a.png` | `files={"file": open("a.png", "rb")}` | Multipart upload |
| `-b "k=v"` | `cookies={"k": "v"}` | Request cookies |
| `-L` | nothing to add | requests follows redirects by default |
| `-k` | `verify=False` | Skips TLS checks; avoid outside local testing |
| `-G -d q=x` | `params={"q": "x"}` | Query string instead of body |

## Let a converter do the first pass

Typing that table out for a long command is tedious. AyeTab handles the parts that show up in almost every API example: the URL, the `-X` method, every `-H` header and a `-d`, `--data` or `--data-raw` body. Paste the command, set the toggle to Python, and copy the result. It joins commands that are split over several lines with backslashes, and it does the work in your browser tab, so nothing you paste goes to AyeTab's servers.

What you get back is plain requests code ending in `print(response.text)`. Treat it as a starting point and apply the cleanups below.

## Three cleanups after converting

**Switch JSON bodies to `json=`.** A converter keeps the body as a string passed to `data`. If the body is JSON, replacing it with a Python dict passed to `json=` is easier to edit, and requests sets the content type for you.

**Move secrets out of the code.** Commands copied from docs or dev tools often hold a bearer token or a session cookie. Read it from an environment variable with `os.environ` instead of pasting the literal value into a file you might commit.

**Add a timeout and a status check.** requests has no timeout unless you set one, so a hung server can block a script forever. Add `timeout=10` and call `response.raise_for_status()` before using the reply.

## Where AyeTab stops

The AyeTab converter is built for the common shape of header plus body. Uploads with `-F`, basic auth with `-u` and query flags such as `-G` are left for you to add using the table. If you convert commands like that often, [curlconverter](https://curlconverter.com/), an open source tool, parses many more curl options and writes code for many more languages, and it is the better choice for that job.

For quick conversions during the day, AyeTab is the pick, mainly because it is already open: the [AyeTab extension for Chrome](https://ayetab.com) puts the converter, a JSON formatter and the other tools on every new tab and in a side panel, and Ctrl+K jumps straight to any of them.

## A note for monitoring scripts

Many people convert curl to requests to schedule a check on an endpoint: a health URL, a price API, a status page. Once the request works, wrap it in a function, log `response.status_code` and the time taken, and run it from cron or a task scheduler. Keep the timeout short so one slow response does not stall the next run.

## Frequently asked questions

### How do I send JSON with requests instead of a string?

Pass a dict to the json argument. requests encodes it and sets the Content-Type header to application/json for you.

### What is the requests version of curl -L?

You do not need one. requests follows redirects by default for every method except HEAD.

### Does requests have a default timeout?

No. If you do not pass timeout, a request can wait indefinitely, so add one to every call in a script.

## Sources

- [cURL to Code converter](https://app.ayetab.com/tools/curl-code), AyeTab
- [AyeTab](https://ayetab.com), AyeTab
- [Requests quickstart](https://requests.readthedocs.io/en/latest/user/quickstart/), Requests
- [curl man page](https://curl.se/docs/manpage.html), curl
- [curlconverter](https://curlconverter.com/), curlconverter
