Python package for extracting tagged code snippets from local files or remote sources.
Project description
SnipTeX is a Python package for extracting tagged code snippets from local files or remote sources. It serves as the backend for the SnipTeX LaTeX package, enabling dynamic inclusion of code snippets directly in documents.
Quick example
Source file
# sniptex-start demo
def main():
x = 1
y = 2
print(x + y)
return 0
# sniptex-end demo
if __name__ == "__main__":
import sys
sys.exit(main())
CLI usage
sniptex --help
Write the snippet to stdout:
sniptex -s example.py -t demo
Write the snippet to a file:
sniptex -s example.py -t demo -o out/out.txt
Get snippet from URL:
sniptex -s https://raw.githubusercontent.com/brozrost/sniptex/main/docs/example.py -t demo
Python usage
from sniptex import extractor
snippet = extractor.extract_from_file("example.py", "demo")
Tag format
SnipTeX extracts code between two matching markers:
sniptex-start <tag>
...
sniptex-end <tag>
Tags are case-sensitive and markers must appear on separate lines.
Supported sources
- Local file paths
- Remote URLs (e.g. GitHub raw files)
Error handling
SnipTeX raises errors when:
- the tag is not found
- start/end markers are mismatched
- multiple start markers exist
- the source cannot be fetched
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 sniptex-1.0.1.tar.gz.
File metadata
- Download URL: sniptex-1.0.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ab3bf0ba1465ce6d94e3f825e58123297a93b13c91e4160af11bd9183b072ba
|
|
| MD5 |
be1667f7daf964da15817f2d90a5a86e
|
|
| BLAKE2b-256 |
e287049195aad4766e0004160ae69d79943694f46a6f4a9e6688a4596f1803f9
|
File details
Details for the file sniptex-1.0.1-py3-none-any.whl.
File metadata
- Download URL: sniptex-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88408955baf40effa68e701068ec5b66d80425b5023ab729b37d19cdba3c94e1
|
|
| MD5 |
55f73f7c6c8b434348ca942a1f6c016c
|
|
| BLAKE2b-256 |
cf3c97bbdce985c28650bca4d24e5358b287ec8c4c6c333806476dd5974d8e6c
|