touchstone.parser
A Python library for Touchstone
.sNpparsing and S‑parameter analysis in RF/microwave engineering.
touchstone.parser is a clean, modular, enterprise-ready Python library for parsing Touchstone (.sNp) files — the industry-standard format for RF and microwave S‑parameter data. It provides strongly typed classes, LINQ-friendly APIs, and seamless integration into simulation and analysis workflows.
✨ Features
- Parse
.sNpfiles into strongly typed Python classes (TouchstoneData,FrequencyPoint,NetworkParameter) - Multi-port support — 1‑port through N‑port networks
- All data formats — Real/Imaginary (RI), Magnitude/Angle (MA), Decibel/Angle (DB)
- All frequency units — Hz, kHz, MHz, GHz with automatic normalization
- All parameter types — S, Y, Z, H, G
- LINQ-friendly APIs — query S‑parameters with
get_s11(data),get_s21(data),data.get_parameter(r, c) - RF calculations — insertion loss, return loss, VSWR out of the box
- Export utilities — CSV export and Touchstone writer for round-trip fidelity
- Minimal dependencies — powered by
numpyfor fast array operations
📦 Installation
pip install touchstone.parser
Or via the PyPI Package Manager:
pip install touchstone.parser
🚀 Quick Start
from touchstone.parser import TouchstoneParser
# Parse a Touchstone file
data = TouchstoneParser.parse("filter.s2p")
print(f"Ports: {data.n_ports}")
print(f"Frequency points: {data.n_freq}")
# Query S21 insertion loss
il = data.to_insertion_loss()
for f, val in zip(data.frequencies, il):
freq_ghz = f / 1e9
print(f"{freq_ghz:.3f} GHz → IL = {val:.2f} dB")
# Filter to a frequency range
passband = data.in_frequency_range(2.0e9, 3.0e9)
# Compute VSWR
vswr = data.to_vswr()
for f, val in zip(data.frequencies, vswr):
print(f"VSWR = {val:.3f}")
# Export to CSV
data.to_csv("output.csv")
📖 API Overview
Parsing
| Method | Description |
|---|---|
TouchstoneParser.parse(filepath) |
Parse from a file path |
TouchstoneParser.parse_string(content, n_ports?) |
Parse from a raw string |
Data Access
| Method | Description |
|---|---|
data.get_s(to_port, from_port) |
Get S‑parameters across all frequencies |
data.frequency |
All frequency values in Hz |
data.s_parameters |
3D numpy array of all parameters |
RF Calculations
| Method | Description |
|---|---|
data.to_insertion_loss() |
|S21| insertion loss in dB |
data.to_return_loss() |
|S11| return loss in dB |
data.to_vswr() |
VSWR from S11 |
Filtering & Export
| Method | Description |
|---|---|
data.in_frequency_range(min_hz, max_hz) |
Filter to frequency range |
data.to_csv(writer) |
Export to CSV file or path |
data.to_csv_string() |
Export to CSV string |
write_snp(data, filepath) |
Write back to Touchstone format |
Utilities
| Method | Description |
|---|---|
normalize_frequency(val, unit) |
Convert to Hz |
db_to_mag(db) |
Convert DB to magnitude |
mag_to_db(mag) |
Convert magnitude to DB |
ma_to_complex(mag, deg) |
Create from MA |
db_to_complex(dB, deg) |
Create from DB |
🏗️ Project Structure
touchstone-python/
├── src/
│ └── touchstone/parser/ # Core library
│ ├── models/ # Domain models (enums, data classes)
│ ├── parsing/ # Parser engine
│ └── utilities/ # Converters, extensions, writer
├── tests/ # pytest test suite
├── docs/ # Sphinx documentation
├── pyproject.toml # Project metadata and dependencies
└── .github/workflows/ # GitHub Actions CI/CD
🔧 Supported Formats
| Feature | Supported |
|---|---|
| Touchstone v1.0 / v1.1 | ✅ |
1‑port (.s1p) |
✅ |
2‑port (.s2p) |
✅ |
Multi-port (.s3p, .s4p, ...) |
✅ |
| Real-Imaginary (RI) | ✅ |
| Magnitude-Angle (MA) | ✅ |
| Decibel-Angle (DB) | ✅ |
| Hz / kHz / MHz / GHz | ✅ |
| S / Y / Z / H / G parameters | ✅ |
| Comments and metadata | ✅ |
| Touchstone v2.0 keywords | 🔜 Planned |
🧪 Running Tests
pytest --verbosity normal
🤝 Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
💬 Community
- ⭐ Star this repo and related RF/microwave projects to help them grow - then mention your project in context to build visibility.
- 💡 Share feedback via GitHub Discussions - we'd love to hear how you're using the library, what's working, and what could be better.
📄 License
This project is licensed under the MIT License.
💖 Support & Funding
If this library helps you in your RF/microwave engineering work, consider supporting its maintenance and the development of new features:
- Sponsor on GitHub
- ⭐ Star the project to help it gain visibility in the engineering community.
📚 Resources
- Touchstone File Format Specification (IBIS)
- S-parameter — Wikipedia
- PyPI Package
- Touchstone .NET Library - check out the .NET version for C#-based workflows.
Made by suryamangaraj · Built for the RF/microwave engineering community 📡
Metadata
Release files for touchstone.parser 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| touchstone_parser-1.0.6.tar.gz | 33.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| touchstone_parser-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 64.6 kB
Release files / touchstone_parser-1.0.6.tar.gz
| Download URL | touchstone_parser-1.0.6.tar.gz |
|---|---|
| Size | 33.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30ae2c9530e8f1c143c3c1fd0495975414da95c74ae61b1a276d4ed5468f2a59
|
|
BLAKE2b-256 checksum How to use checksums |
fc719493fb8df7c68430980786b42554087455dc6472f6f576e5a5d072145a2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 24, 2026.
Transparency logRelease files / touchstone_parser-1.0.6-py3-none-any.whl
| Download URL | touchstone_parser-1.0.6-py3-none-any.whl |
|---|---|
| Size | 31.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69112a027c7a2e51cf67b65c522833e80129bfaa96aa0381ed4b8ae80f5f6718
|
|
BLAKE2b-256 checksum How to use checksums |
f268ec74fadf4d6673b9621729ad74bbfbb207cd541a45e68e42d709001b340e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 24, 2026.
Transparency log