Skip to main content

PyPI PyPI Build Status

har2locust

Creating a locust file from scratch is sometimes hard. Don't you wish you could just generate it automatically from a browser session?

Well, now you can! har2locust converts your browser recordings (HAR files) into locust files.

Here's an example of a generated file.

At its core har2locust uses a jinja2 template to define the output. You can easily change that to customize your output, or you can go even further and use the plugin system to make any kind of changes to the processing/output.

Installation

pip install har2locust

Usage

  1. Navigate the web with your browser while recording your activity. Then export the recording into a HAR file. Here is an example using Chrome Devs Tools har.gif

  2. Run har2locust myrecording.har > locustfile.py

> har2locust --help
usage: har2locust [-h] [-t TEMPLATE] [--plugins PLUGINS] [--disable-plugins DISABLE_PLUGINS]
                  [--resource-types RESOURCE_TYPES] [--version] [--loglevel LOGLEVEL]
                  input

positional arguments:
  input                 har input file

options:
  -h, --help            show this help message and exit
  -t TEMPLATE, --template TEMPLATE
                        jinja2 template used to generate locustfile. Defaults to locust.jinja2. Will check current
                        directory/relative paths first and har2locust built-ins second
  --plugins PLUGINS     Comma separated list of extra python files to source OR packages to import, containing
                        decorated methods for processing the har file.
  --disable-plugins DISABLE_PLUGINS
                        Temporarily disable default plugins. Specified by comma separated list of default plugin
                        python files to source.
  --resource-types RESOURCE_TYPES
                        Commas separated list of resource types to be included in the locustfile. Supported type are
                        `xhr`, `script`, `stylesheet`, `image`, `font`, `document`, `other`. Defaults to
                        xhr,document,other.
  --version, -V         show program's version number and exit
  --loglevel LOGLEVEL, -L LOGLEVEL

Simplest usage:
har2locust myrecording.har > locustfile.py

Load extra plugins by import path and/or filename:
har2locust --plugins har2locust.extra_plugins.plugin_example,myplugin.py myrecording.har

Disable one of the default plugins:
har2locust --disable-plugins=rest.py myrecording.har

Parameters can also be set using environment variables or config files (har2locust.conf or ~/.har2locust.conf) For details about how to set parameters see https://goo.gl/R74nmi
  1. Run locust!

Advanced usage

  • Filter your recording using the files .urlignore and .headerignore (read from your current directory). Populate them with regexes to filter any unwanted requests or headers from your recordings. Some headers are always ignored (cookie, content-length and chrome's "fake" headers) Here are some examples: .urlignore, .headerignore

  • Use the plugin system for more advanced processing.

Notes

har2locust builds upon har2py, modified to generate a locustfile instead of a basic Python file and extended to support plugins.

har2locust is very new, and before 1.0 there may be changes to interfaces without notice. If you encounter an issue, PRs are very welcome.

Also, dont expect that the generated file will always be very useful out of the box. You'll want to add response validations to ensure the quality of your test.

Metadata

Release files for har2locust 0.9.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for har2locust 0.9.4
File Size Uploaded Provenance
har2locust-0.9.4.tar.gz 25.6 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for har2locust 0.9.4
File Interpreter ABI Platform
har2locust-0.9.4-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 MB

Release files / har2locust-0.9.4.tar.gz

Download URL har2locust-0.9.4.tar.gz
Size 25.6 MB
Tags Source
SHA-256 checksum
How to use checksums
333ed347fb3a6e3c36dfde587a922cab4949905c7db3d9008e727b57468ddbbc
BLAKE2b-256 checksum
How to use checksums
63c76d9a7333c53ba9968eef82466cb41ab67431986ab69d79cbcdd504eaa42e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / har2locust-0.9.4-py3-none-any.whl

Download URL har2locust-0.9.4-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc763ba2462a27725a4a62aad424ac9f31c1da308e316963e883fdf9d4aaf1c7
BLAKE2b-256 checksum
How to use checksums
0aeda2b40076f41dfa663753ca2f1671401eb429877a2094412bd9673f9b6e03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for har2locust 0.9.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page