Skip to main content

tagsnip is a Python CLI tool for extracting tagged code snippets from local files or remote URLs, such as GitHub raw files. It serves as the backend for the tagsnip LaTeX package and enables dynamic inclusion of code snippets directly in LaTeX documents.

Installation

Install tagsnip from PyPI:

pip install tagsnip

After installation, the command tagsnip should be available in your shell:

tagsnip --help

Usage

tagsnip -s <source> -t <tag> [-o <output>]
tagsnip -c <output>

Command-line options

-s, --source   Local file path or remote URL.  
-t, --tag      Snippet tag to extract.  
-o, --output   Optional output file path.
-c, --cleanup  Removes temporary files at specified path. 

--source and --tag are mandatory arguments. If --output is provided, tagsnip writes the extracted snippet to the selected file. Otherwise, the snippet is written to stdout.

When --output is used, tagsnip also writes a metadata file next to the output file. For example, if the output file is snippet.tmp, then the metadata file is snippet.tmp.meta. Both files can be removed using the --cleanup option.

The metadata file contains the original start and end line numbers of the extracted snippet. This is used by the LaTeX package to preserve source line numbering.

Supported sources

  • Local text files
  • Remote text files available over HTTP or HTTPS
  • GitHub raw file URLs

Tag format

tagsnip extracts code between two matching markers:

tagsnip-start <tag>
...
tagsnip-end <tag>

Tags are case-sensitive. Markers must appear on separate lines. The tag must follow the marker name after one space.

For example:

# tagsnip-start demo
print("This line will be extracted.")
# tagsnip-end demo

The marker lines themselves are not included in the extracted snippet.

Error handling

tagsnip reports errors when:

  • The tag is not found
  • Start/end markers are mismatched
  • Multiple start markers exist
  • The source cannot be fetched

Quick example

Example source file

# tagsnip-start demo
def main():
    x = 1
    y = 2
    print(x + y)

    return 0
# tagsnip-end demo

if __name__ == "__main__":
    import sys
    sys.exit(main())

CLI usage

Write the snippet to stdout:

tagsnip -s example.py -t demo

Write the snippet to a file:

tagsnip -s example.py -t demo -o out/out.txt

Get snippet from URL:

tagsnip -s https://raw.githubusercontent.com/brozrost/tagsnip/main/docs/example.py -t demo

Remove temporary files:

tagsnip -c out/out.txt

Python usage

from tagsnip import extractor

snippet = extractor.extract_from_file("example.py", "demo")

Compatibility note

The Python package and the LaTeX package should be kept in sync. Backwards compatibility is not guaranteed.

Metadata

Release files for tagsnip 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tagsnip 1.0.2
File Size Uploaded Provenance Actions
tagsnip-1.0.2.tar.gz 9.4 kB With provenance Details for tagsnip-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tagsnip 1.0.2
File Interpreter ABI Platform Actions
tagsnip-1.0.2-py3-none-any.whl Python 3 none any Details for tagsnip-1.0.2-py3-none-any.whl

Total release size: 16.2 kB

Release files / tagsnip-1.0.2.tar.gz

Download URL tagsnip-1.0.2.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d909bee2093bae5e714ea18a9435050be1f87a15fc569c5fa8d7945984e9b1da
BLAKE2b-256 checksum
How to use checksums
847a0e66e9c1be67f4ae6aa8f1d7a5839535b49fe284e275522ebd382b61d272
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 Jul 15, 2026.

Transparency log

Release files / tagsnip-1.0.2-py3-none-any.whl

Download URL tagsnip-1.0.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e3e6f4085a60e506c6403821f2eedc123766723c9661af9b78c4be1ebbf61d2
BLAKE2b-256 checksum
How to use checksums
bfa7fe2ad79d256f32dede5a77bea60bf24fab9f796844843197680ba56df38d
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 Jul 15, 2026.

Transparency log

Security for tagsnip 1.0.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tagsnip-1.0.2.tar.gz

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 Jul 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page