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.0.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.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrestfile-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 1954c91abca24e556e10c6854e31ba39378691177c4062d1187841fc96c75525
MD5 ae4b4ebcd34c51671264ed2140f8c542
BLAKE2b-256 13faca328af3514d4122044b5608be6332931f3cb243f2081bd722173fc10911

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrestfile-0.2.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: pyrestfile-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06f22007853fab4905d1e79c1408b194c7604090573464aad5b211c547478038
MD5 8718a21ee73c68770941e93c1a659bdf
BLAKE2b-256 6cedccb709042146002c2fe2ab9e040e595d16fe7887f5a7bcf028ba621b08e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrestfile-0.2.0-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