Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Requests · Function

requests.put

Sends an HTTP PUT request and returns the resulting Response. The request body may be supplied with data or json, while other request options are passed as keyword arguments.

How it works

requests.put creates and sends an HTTP PUT request to the supplied URL. It can place dictionary, tuple-list, byte, or file-like data in the request body and accepts the optional keyword arguments supported by requests.request, returning the resulting Response.

Syntax

requests.put(url: _t.UriType, data: _t.DataType = None, **kwargs: Unpack[_t.DataKwargs]) → Response

Parameters

NameTypeDescription
url_t.UriTypeURL for the new Request object.
data_t.DataType = NoneOptional dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.
jsonJSON-serializable Python objectOptional JSON-serializable Python object to send in the body of the Request.
**kwargsUnpack[_t.DataKwargs]Optional arguments accepted by request.

Returns

Response object (requests.Response).

Key points

  • Use this function when the HTTP method should be PUT.
  • The required url argument specifies the destination for the request.
  • The data argument supports several body representations, including mappings, tuple sequences, raw bytes, and streams.
  • The json keyword argument is available for sending a serializable Python value as the request body.
  • The call produces a Response containing the server's result.

Common mistakes

  • Keyword arguments are forwarded to the general request function, so their meaning and behavior come from that function's supported options.

Example: Send a PUT request

import requests

response = requests.put(
    "https://httpbin.org/put",
    data={"key": "value"},
    timeout=10,
)
response.raise_for_status()
print(response.status_code)

Sends form-style data in a PUT request and checks that the server returned a successful status.

When to use it

Resource replacement or update

Updating a resource at a known endpoint.

Form-style request body

Submitting structured form fields to a PUT endpoint.

JSON API update

Sending serialized application data to an API.

Interview questions

QWhat does requests.put return and what are its main inputs?

It sends a PUT request and returns a requests.Response object. The URL identifies the destination, while data optionally supplies the request body.

Follow-up: How would you send JSON? Pass a JSON-serializable Python object through the documented json keyword argument.

QWhat types can the data argument accept?

data may be a dictionary, a list of tuples, bytes, or a file-like object. These values are used as the body of the Request.

Follow-up: Why might a list of tuples be useful? It can represent repeated form-field names without collapsing them into one mapping entry.

QHow does requests.put relate to requests.request?

The function is a convenience wrapper for the PUT HTTP method. It accepts the same optional request arguments as the general request function, including json when a JSON body is needed.

Follow-up: What should be checked after receiving the response? Inspect the Response or call raise_for_status to surface unsuccessful HTTP status codes.

  • requests.request
  • requests.post
  • requests.patch
  • requests.delete
  • requests.Response

Source: Developer Interface — Requests 2.34.2 documentation. Checked 2026-10-15.