Back to blog

    Conversion guides

    How to convert cURL to Python requests

    The easiest way to convert cURL to Python is to map the URL, method, headers, body, and auth settings into a requests call.

    7 min readUpdated 2026-04-28

    A simple conversion

    A basic GET request in curl maps to requests.get in Python. The URL stays the same, and the response object gives you status code, headers, and body access.

    curl input
    curl https://api.github.com/repos/curl/curl

    Python requests output

    The equivalent Python code imports requests and calls the method that matches the HTTP request.

    Python output
    import requests
    
    response = requests.get('https://api.github.com/repos/curl/curl')
    print(response.status_code)
    print(response.json())

    Headers, JSON, and auth

    Headers usually become a Python dictionary. JSON request bodies usually become dictionaries passed with the json parameter. Basic auth can become an auth tuple, and bearer auth stays in the Authorization header.

    When to review generated code

    Generated code should still be reviewed before production use. Check timeout handling, error handling, retries, secret storage, and whether the API client should be wrapped in a reusable function.

    Try it with curlcode

    Have a curl command already? Paste it into one of the converters below to generate language-specific HTTP request code.

    Frequently asked questions

    Which Python library should I use?

    Most developers use requests. If you need only the standard library, use http.client.

    Can curl headers convert to Python?

    Yes. They usually become a headers dictionary.

    How do I handle JSON responses?

    Use response.json() when the API returns JSON.

    Should generated Python code include timeouts?

    For production, yes. Add a timeout to avoid hanging forever on slow requests.

    Related guides