🔁 cURL 转 Python 转换器 — 生成 requests 代码

Convert any cURL command to Python requests code instantly. Supports headers, POST body, auth, JSON. Free online curl to Python converter.

Paste your curl command and select the Python tab to get production-ready Python requests code. Handles all curl flags: -H headers, -d POST data, -u basic auth, -X methods, and JSON bodies. Copy and paste straight into your project.

How to Use

1

Paste your cURL command

Paste your full curl command (starting with "curl") into the input area. Multi-line commands with \ are supported.

2

Choose a language

Click a language tab: Python, JavaScript, PHP, or Go. The code updates instantly.

3

Copy the code

Click Copy to copy the generated code. It handles headers, auth, and JSON bodies.

Frequently Asked Questions

What is a cURL command? +
cURL is a command-line tool for making HTTP requests. Developers use it to test APIs, download files, and debug network requests. Format: curl [options] URL. Common flags: -X (method), -H (header), -d (data), -u (auth).
What languages are supported? +
This tool generates code for Python (requests library), JavaScript (fetch API), PHP (curl extension), and Go (net/http package). Each output is idiomatic and production-ready.
How do I convert a curl with headers? +
Include -H flags in your curl command, e.g.: curl -H "Authorization: Bearer token" -H "Content-Type: application/json" https://api.example.com. All headers are extracted and included in the generated code.
Does it support POST with JSON body? +
Yes. Include -d '{"key":"value"}' or --data-raw with your JSON. The tool detects JSON content and formats it properly for each language.
What about Basic Auth? +
curl -u username:password is supported and converted to the appropriate auth mechanism in each language: HTTPBasicAuth in Python, btoa() in JS, CURLOPT_USERPWD in PHP, and SetBasicAuth in Go.


完整指南:cURL转代码工具

什么是这个工具?

curl命令转换为Python(requests)、JavaScript(fetch)、PHP、Go、Ruby等语言的等效代码。API文档(Stripe、OpenAI、Twilio)使用curl作为标准——将这些示例转换为可用于生产的代码。

如何使用

  1. 粘贴完整的curl命令,包括头部和正文。
  2. 选择目标语言
  3. 复制生成的代码集成到项目中。

专业技巧

🧰 50+ Tools