Skip to main content

Easy-to-use API testing with DevOps automation support

Project description

Drun: Modern HTTP API Testing Framework

English | 中文

Version Python License

Documentation · GitHub

Drun is a YAML-driven HTTP API testing framework. It lets you describe requests, variable extraction, checks, suite orchestration, and report output in concise YAML, making API validation, debugging, and CI/CD execution easier to maintain.

Highlights

  • YAML DSL: write tests with config, steps, extract, check, and caseflow.
  • Template system: supports $var, ${ENV(KEY)}, ${uuid()}, and other dynamic expressions.
  • Rich checks: built-in checks such as eq, contains, regex, len_eq, and gt.
  • Test orchestration: supports suites, invoke, step repeat, and tag filtering.
  • Sleep steps: supports explicit wait DSL such as sleep: 2000, using milliseconds.
  • Outputs: HTML, JSON, Allure reports, logs, and generated code snippets.
  • Debug-friendly: drun q for quick requests, plus converters from cURL, Postman, HAR, and OpenAPI.

Installation

Python 3.10+ is recommended.

pip install drun

If you prefer uv:

uv venv
source .venv/bin/activate
uv pip install drun

Quick Start

1. Initialize a Project

drun init myproject
cd myproject

Default scaffold:

myproject/
├── testcases/
├── testsuites/
├── data/
├── converts/
├── logs/
├── reports/
├── snippets/
├── .env
└── Dhook.py

2. Configure Environment Variables

.env

BASE_URL=https://api.example.com
API_KEY=demo-token

3. Write Your First Test

testcases/test_user_api.yaml

config:
  name: User API Test
  base_url: ${ENV(BASE_URL)}
  tags: [smoke, user]

steps:
  - name: Create User
    request:
      method: POST
      path: /users
      headers:
        Authorization: Bearer ${ENV(API_KEY)}
      body:
        username: test_${uuid()}
        email: test@example.com
    extract:
      userId: $.data.id
    check:
      - eq: [status_code, 201]
      - regex: [$.data.id, '^\d+$']

  - name: Get User
    request:
      method: GET
      path: /users/${ENV(USER_ID)}
      headers:
        Authorization: Bearer ${ENV(API_KEY)}
    check:
      - eq: [status_code, 200]

4. Run Tests

drun run testcases/test_user_api.yaml -env dev
drun run test_user_api -env dev
drun run testcases -env dev -k "smoke and not slow"
drun run test_user_api -env dev -html reports/report.html

Notes:

  • .yaml can be omitted in run targets.
  • Temporary single-file runs write only one log file to the current directory.
  • Scaffolded project runs keep outputs in logs/, reports/, and snippets/.

Common Patterns

Single Test File

config:
  name: Login API
  base_url: ${ENV(BASE_URL)}

steps:
  - name: Login
    request:
      method: POST
      path: /login
      body:
        username: admin
        password: pass123
    extract:
      token: $.data.token
    check:
      - eq: [status_code, 200]

Suite File

config:
  name: Smoke Suite

caseflow:
  - name: Login
    invoke: test_login
  - name: Profile
    invoke: test_profile

Data-Driven Execution

config:
  name: Batch Registration
  parameters:
    - csv:
        path: data/users.csv

steps:
  - name: Register $username
    request:
      method: POST
      path: /register
      body:
        username: $username
        email: $email
    check:
      - eq: [status_code, 201]

Repeated Steps

steps:
  - name: Retry Health Check
    repeat: 3
    request:
      method: GET
      path: /health
    check:
      - eq: [status_code, 200]

Sleep Steps

steps:
  - name: Wait for stabilization
    sleep: 2000

  - name: Wait from variable
    sleep: ${wait_ms}

Common Commands

Run and Debug

drun run PATH -env dev
drun q https://api.example.com/ping
drun q https://api.example.com/users -X POST -d '{"name":"alice"}'
drun tags testcases
drun check testcases
drun fix testcases

drun check aggregates YAML/DSL authoring diagnostics with stable error codes such as DRUN-YAML-003, file locations, fix hints, and minimal examples. drun run still stops quickly on blocking YAML errors.

Format Conversion

drun convert sample.curl -outfile out.yaml
drun convert-openapi spec/openapi/ecommerce_api.json -output-mode split -outfile converted/ecommerce.yaml
drun export curl testcases/test_user_api.yaml -outfile request.curl

Report Server

drun server
drun server -port 8080

After startup, you can browse the report list and detail pages in the browser.

Reports and Outputs

  • HTML: good for local viewing and sharing.
  • JSON: good for CI pipelines and machine consumption.
  • Allure: good for integration with test platforms.
  • Snippets: generates Shell or Python request scripts for replaying requests.

Examples:

drun run testcases -env dev -html reports/report.html
drun run testcases -env dev -allure-results allure-results
allure serve allure-results

Develop from Source

git clone https://github.com/Devliang24/drun.git
cd drun
pip install -e ".[dev]"
python -m pytest -q
python -m drun.cli --version

Repository overview:

  • drun/: core implementation.
  • tests/: regression tests.
  • spec/: sample OpenAPI specs.
  • CHANGELOG.md: version history.
  • drun-usage/: local deep-usage skill for AI coding assistants, covering drun YAML, CLI usage, conversion, and troubleshooting.
  • AGENTS.md: contributor rules and local development notes.

AI Assistant Collaboration

This repository includes a local skill at drun-usage/. Its purpose is to help AI coding assistants answer drun questions using the repository's actual CLI and DSL behavior, and to return runnable YAML, CLI commands, and troubleshooting guidance instead of generic API testing advice.

Typical use cases:

  • Generate drun YAML cases
  • Explain invoke, invoke_case_name, invoke_case_names, repeat, and sleep
  • Design drun run, drun q, convert, convert-openapi, and export curl commands
  • Explain HTML / JSON / Allure / snippet / server
  • Troubleshoot drun errors

Claude Code

If you use Claude Code, the safest approach is to mention the skill explicitly or ask it to read the skill files before working.

Example prompts:

Use drun-usage to generate a drun testsuite for login and profile lookup.
Read drun-usage/SKILL.md first, then convert this curl command into drun YAML and provide the run command.

Codex

If you use Codex, explicitly naming drun-usage works well. Natural trigger phrases such as "drun YAML", "drun invoke", or "drun troubleshooting" are also useful. When collaborating in this repository, read AGENTS.md first.

Example prompts:

Use drun-usage to explain the difference between invoke_case_name and invoke_case_names, and give me a runnable example.
Help me debug this drun error, and consult drun-usage/references/troubleshooting.md if needed.

OpenCode

If you use OpenCode and your workflow does not automatically discover local skills, explicitly ask it to read drun-usage/SKILL.md first, then load the matching file under references/ as needed.

Example prompts:

Read drun-usage/SKILL.md first, then generate a drun YAML case for file upload and provide the matching run command.
Read drun-usage/references/debug-convert-export.md and give me a drun convert-openapi command for this spec.

Usage Tips

  • If you want runnable YAML and commands, mention drun-usage explicitly
  • If you only need one DSL concept, ask directly, for example: "Explain drun repeat"
  • If you change CLI, DSL, reporting, or troubleshooting behavior, update drun-usage/ accordingly

Use Cases

  • HTTP API regression testing
  • Smoke testing and release verification
  • Data-driven execution
  • API debugging and request replay
  • CI/CD quality gates for interfaces

Contributing

Before opening a PR, run at least:

python -m pytest -q
drun --help

If you are contributing within this repository, read AGENTS.md first.

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drun-7.2.22.tar.gz (173.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drun-7.2.22-py3-none-any.whl (175.7 kB view details)

Uploaded Python 3

File details

Details for the file drun-7.2.22.tar.gz.

File metadata

  • Download URL: drun-7.2.22.tar.gz
  • Upload date:
  • Size: 173.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for drun-7.2.22.tar.gz
Algorithm Hash digest
SHA256 a29f0160cf320c0f735adae5433a4b0b98d9cce9d6034e22092b3283f4e5bd76
MD5 93d289263650f4147d1fe441fc4aa627
BLAKE2b-256 925a2077d1541e8a928c9399746d488844eec50a272c6859c53e9e06383acef3

See more details on using hashes here.

File details

Details for the file drun-7.2.22-py3-none-any.whl.

File metadata

  • Download URL: drun-7.2.22-py3-none-any.whl
  • Upload date:
  • Size: 175.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for drun-7.2.22-py3-none-any.whl
Algorithm Hash digest
SHA256 b22ff6f9d8d8b4d4932d58db8fff62443a5c2f49f6fa59627d608e4e0cc38d54
MD5 d75495439fb74126dbb8860099288a95
BLAKE2b-256 f2b1679df460cb24e49d95d7cc8e8f2a1658ba2f7159711b577a21d798b8dd18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page