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/jsonis 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4a95597f1ee45793e06554529acc286c618518a366c8c0a13423affcd82a3ed
|
|
| MD5 |
c75700b4184c4598754bc9c6d97ddcc3
|
|
| BLAKE2b-256 |
3646d4dd354b43f7e7f9c6acf8532fb4d0e8c36c13fb474ca436177c33a7cc94
|
Provenance
The following attestation bundles were made for pyrestfile-0.2.1.tar.gz:
Publisher:
publish.yaml on abelcastilloavant/pyrestfile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrestfile-0.2.1.tar.gz -
Subject digest:
c4a95597f1ee45793e06554529acc286c618518a366c8c0a13423affcd82a3ed - Sigstore transparency entry: 198375543
- Sigstore integration time:
-
Permalink:
abelcastilloavant/pyrestfile@3ecdc7693130994da623447b3b76156710a4910e -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/abelcastilloavant
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@3ecdc7693130994da623447b3b76156710a4910e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9586d4a9737810bb2ebc4c723c233a83d9576c6f9e6d1cd021873e12b01c07b7
|
|
| MD5 |
a276a3d5d73ebc784449882c79b6b8d4
|
|
| BLAKE2b-256 |
5320eebf839f190500e0c0d2852ef710622551e8c4974e577827733c3cfe7a2d
|
Provenance
The following attestation bundles were made for pyrestfile-0.2.1-py3-none-any.whl:
Publisher:
publish.yaml on abelcastilloavant/pyrestfile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrestfile-0.2.1-py3-none-any.whl -
Subject digest:
9586d4a9737810bb2ebc4c723c233a83d9576c6f9e6d1cd021873e12b01c07b7 - Sigstore transparency entry: 198375544
- Sigstore integration time:
-
Permalink:
abelcastilloavant/pyrestfile@3ecdc7693130994da623447b3b76156710a4910e -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/abelcastilloavant
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@3ecdc7693130994da623447b3b76156710a4910e -
Trigger Event:
push
-
Statement type: