In this tutorial, we will test POST Request in Python using Requests.
Prerequisite:
- Python is installed on the machine
- PIP is installed on the machine
- PyCharm or other Python Editor is installed on the machine
If you need help in installing Python, please refer to this tutorial – How to Install Python on Windows 11.
If you need help in installing PyCharms, please refer to this tutorial – How to install PyCharms on Windows 11.
Below is the example of POST Request.

Installation of Python Requests Module
Step 1 – If you are using PyCharm IDE then you need to install the Request library. Execute the below command using pip.
pip install -U requests
Step 2 – Install Pytest
pip install -U pytest
Step 3 – Create a new project folder and open it in PyCharm.

Step 4 – Go to the project folder and Create a new file, name it “PostRequest.py”.

Step 5 – Create the test
Import the required packages.
The POST method is used to get the resource from the server and returns 201 for successful call.
import requests
ENDPOINT = 'https://reqres.in/api/users'
def test_create_user():
response = requests.post(ENDPOINT, {"name": "Vibha", "job": "CTO"})
response_body = response.json()
print(response_body)
assert response.status_code == 201
assert response_body["name"] == "Vibha"
assert response_body["job"] == "CTO"
requests.post(url, data=data) – function sends a POST request to the specified URL with the provided data. The data dictionary contains the key-value pairs that we want to send in the POST request payload. You can modify it based on the requirements of the API we are working with.
The response object contains information about the response, including the status code and the response content.
The output of the above program is

In the above example, we have passed the request body in the requests.post(). In the below example, will define a variable and assign the request body to it.
def test_create_user1():
payload = {
"name": "Vibha",
"job": "CTO"
}
response = requests.post(ENDPOINT, payload)
response_body = response.json()
print(response_body)
assert response.status_code == 201
assert response_body["name"] == "Vibha"
assert response_body["job"] == "CTO"
The output of the above program is

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!