The requests library is a powerful and user-friendly tool in Python for making HTTP requests. The PUT method is one of the key HTTP request methods used to update or create a resource at a specific URI.
Working of HTTP PUT Method
If the resource exists at the given URI, it is updated with the new data.
If the resource does not exist, the server can create it at that URI.
The request includes the data to be stored in the request body.
It's idempotent, meaning sending the same request multiple times results in the same outcome (unlike POST).
Syntax
requests.put(url, params={key: value}, **args)
Parameters:
url: The target endpoint.
data: Dictionary or string to be sent in the body (often form or JSON data).
args: Optional parameters like headers, authentication, timeout, etc.
Installation
To use the requests module, we need to first install it using this command:
pip install requests
Example – Making a PUT Request
In this example, we are going to make a real PUT Request using httpbin.org, a public testing API.