npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

swagger-to-locustfile

v0.6.1

Published

A CLI tool that creates locust.io config tasks file from swagger json spec

Readme

swagger-to-locustfile

A CLI tool that creates locust.io tasks file (locustfile.py) from Swagger/OpenAPI Spec.

Requirements

  • Node JS (4.0 & up)

Installation

Best option is:

npm install swagger-to-locustfile

Or you can install from a clone of the repo:

  1. $ git clone [email protected]:lieldulev/swagger-to-locustfile.git
  2. $ cd swagger-to-locustfile
  3. $ npm -g install
  4. You are good to go.

Currently Supports

  • Grabbing the host field for the spec.
  • Generating tasks for GET endpoints only.
  • Replacing Path-Parameters holders with their default value.
  • Appending the required query string parameters and their default values.
  • Swagger/OAI vendor extensions (x-locust-import and x-locust-value) to override default values with custom python expressions.
  • Command Line Options allow overriding min_wait, min_max and host

Future Plans / Open Issues

  • Support POST / PUT endpoints
  • Support required headers

Usage

Basically:

$ swagger2locust /path/to/swagger.json > /tmp/locustfile.py

Or you can pipe the spec:

$ cat /path/to/spec.yaml | swagger2locust

Full Usage:

  Usage: swagger2locust [options] <file>

  Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -m, --min <n>      minimum time, in milliseconds, that a simulated user will wait between executing each task (default: 1000).
    -x, --max <n>      maximum time, in milliseconds, that a simulated user will wait between executing each task (default: 3000).
    -H, --host <host>  The host attribute is a URL prefix (i.e. “http://google.com”) to the host that is to be loaded.

Custom Swagger/OAI fields

x-locust-import

You can add x-locust-import to your root node (same level as host field) to specify extra imports for your locust file. This is useful if you need access to an import when you write an expression in x-locust-value.

So for the following swagger spec:

from locust import HttpLocust, TaskSet, task
import time

class MyTaskSet(TaskSet):
...

x-locust-value

x-locust-value allows you to write a python expression that replaces the hardcoded default value of a field. Example:

The following spec file

Will result in the following line in locustfile.py (x-locust-value overrrides default):

...
@task
    def get_required_qs_params_with_x_locust_value(self):
        self.client.get("/api/v1/required/qs/params-with-x-locust-value?some_required_timestamp_param={0}".format(str(int(time.time()))))
...

While omitting x-locust-value field will result in the following line:

...
@task
    def get_required_qs_params_without_x_locust_value(self):
        self.client.get("/api/v1/required/qs/params-with-x-locust-value?some_required_timestamp_param={0}".format("1455134652"))
...

Contribute

  • fork
  • create a branch on your fork.
  • pull-request to master branch here.
  • win.

License

ISC License (ISC)

Copyright (c) 2016, Liel Dulev

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.