Load testing using LOCUST Last Updated : 28 Apr, 2025 Comments Improve Suggest changes 6 Likes Like Report Locust is an open-source load-testing tool. Load testing is a type of software testing that is conducted to check the tolerance/behavior of the system under a specific expected load. The target of locust is load-testing websites and checking the number of concurrent users a system can handle. During a locust test, a swarm of locusts will attack the target i.e website. The behavior of each locust is configurable and the swarming process is monitored from a web UI in real time. Specialty of locust: Test scenarios can be written in PythonDistributed and scalableWeb-based UIAny system can be tested using this tool Installation: Locust can be installed with pip. pip install locust Once the locust is successfully installed, a locust command should be available in your shell. To see more available options: locust --help Getting started: Python3 from locust import HttpUser, TaskSet, task from locust import ResponseError import json class UserBehavior(TaskSet): def __init__(self, parent): super(UserBehavior, self).__init__(parent) self.token = " " self.headers = {} def on_start(self): # The on_start method is called # when a simulated user starts # executing that TaskSet class self.token = self.login() self.headers = {'Authorization': 'Bearer {}'.format(self.token)} self.login() def login(self): # admin login and retrieving it's access token response = self.client.post( & quot / login/" , data={'username': 'admin', 'password': 'ZYT5nsg3565!'}) return json.loads(response._content)['access'] class WebsiteUser(HttpUser): # The task_set attribute should point # to a TaskSet class which defines # the behaviour of the user task_set = UserBehavior min_wait = 5000 max_wait = 9000 Start locust: To run the above code, create a Python file named locustfile.py, and open the terminal in the directory of the above created file. Then write the following command in the terminal. locust Note: By default locust searches for locustfile.py. After the successful execution of the above command, you should open a browser and hit http://127.0.0.1:8089 The Locust UI will appear like below: Create Quiz Comment R RiyaKalia Follow 6 Improve R RiyaKalia Follow 6 Improve Article Tags : Technical Scripter Python Technical Scripter 2019 Python Testing Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like