Skip to main content

Parse VS Code-style .rest files into request objects

Project description

pyrestfile

Parse VS Code REST‑Client .rest files into plain Python objects you can feed to any HTTP client — perfect for load‑testing, fixtures, and scripting.


Why?

The VS Code REST‑Client extension is fantastic for ad‑hoc API calls, but its request files aren’t machine‑readable out of the box. pyrestfile lets you keep those same files in your repository and programmatically use them or validate them within Python.

Features

  • ✅ Parse multiple requests per file (separated by ###).
  • ✅ Preserve method, URL, headers, and body exactly as written.
  • ✅ Ignore full‑line comments (# or //) in the same places VS Code does.
  • ✅ Validate JSON bodies when Content‑Type: application/json is set.
  • ✅ Zero runtime dependencies.

Installation

# library only
pip install pyrestfile

# with dev / test tooling (pytest, coverage, pre‑commit)
pip install ".[dev]"

Quick‑start

from pyrestfile import parse_rest_file

with open("api.rest") as f:
    requests = parse_rest_file(f.read())

for req in requests:
    print(req.method, req.url)

HTTPRequest instances expose:

attribute type example
method str "POST"
url str "https://api.example.com/v1/users"
http_version str "HTTP/1.1" (optional)
headers dict[str, str] {"Content-Type": "application/json"}
body str or None "raw body text"

Using with Locust

# locustfile.py
import random
from locust import HttpUser, task, between
from pyrestfile import parse_rest_file

REQUESTS = parse_rest_file(open("api.rest").read())

class APIUser(HttpUser):
    wait_time = between(1, 3)

    @task
    def random_call(self):
        r = random.choice(REQUESTS)
        self.client.request(
            method=r.method,
            url=r.url,
            headers=r.headers,
            data=r.body,
        )

Run with locust -f locustfile.py.


Development & Testing

# create virtual env of your choice, then
pip install -e ".[dev]"
pre-commit install          # lint on every commit
pytest -q                   # run unit tests

CI

A ready‑made GitHub Actions workflow (.github/workflows/unit_tests_and_code_checks.yaml) runs pre‑commit and pytest on every push.


Roadmap

  • File includes (@file=./payload.json).
  • JavaScript test scripts (low priority).
  • CLI (pyrest run api.rest).

PRs welcome!


License

MIT © 2025 Abel Castillo

Project details


Download files

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

Source Distribution

pyrestfile-0.2.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

pyrestfile-0.2.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pyrestfile-0.2.1.tar.gz.

File metadata

  • Download URL: pyrestfile-0.2.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyrestfile-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c4a95597f1ee45793e06554529acc286c618518a366c8c0a13423affcd82a3ed
MD5 c75700b4184c4598754bc9c6d97ddcc3
BLAKE2b-256 3646d4dd354b43f7e7f9c6acf8532fb4d0e8c36c13fb474ca436177c33a7cc94

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrestfile-0.2.1.tar.gz:

Publisher: publish.yaml on abelcastilloavant/pyrestfile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrestfile-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyrestfile-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyrestfile-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9586d4a9737810bb2ebc4c723c233a83d9576c6f9e6d1cd021873e12b01c07b7
MD5 a276a3d5d73ebc784449882c79b6b8d4
BLAKE2b-256 5320eebf839f190500e0c0d2852ef710622551e8c4974e577827733c3cfe7a2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrestfile-0.2.1-py3-none-any.whl:

Publisher: publish.yaml on abelcastilloavant/pyrestfile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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