Skip to main content

tspng: A Python package for Computer Vision and Machine Learning metadata manipulation

CI Google Colab codecov PyPI Version GitHub Release

A Python package for manipulating Portable Network Graphics (PNG) files with embedded JavaScript Object Notation (JSON) metadata from Machine Learning (ML) applications, such as the TS platform for microscopy image analysis and quantitation. These files have data embedded in the PNG in JSON or as plain text. This package provides extraction of the embedded data and implantation of embedded data into existing PNGs.

Quick Start

Library

  1. Create a virtual environment.

    python3 -m venv .venv
    
  2. Activate the virtual environment.

    source .venv/bin/activate
    
  3. Install tspng.

    python3 -m pip install tspng
    
  4. Create a png_dump.py script to extract embedded data from a PNG file,

    from tspng.extraction import extract_from_file
    
    print(extract_from_file("PATH_TO_FILE").model_dump_json(exclude_none=True, indent=2))
    

    where PATH_TO_FILE is replaced, in quotes, with the path to a .ts.png file on disk.

  5. Run the png_dump.py script,

    $ python3 ./png_dump.py
    {
      // ...  omitted for clarity
    }
    

    where the contents of the PNG metadata will be printed to STDOUT as JSON. The actual contents are omitted for clarity. The jq application can also be used to query and filter the output.

  6. Alternatively, data can be implanted into an existing PNG.

    from tspng.implantation import implant
    
    implant("Path/to/file.json", "Path/to/existing.png", "Path/to/new.png")
    
  7. Creating Metadata for use in other components is also possible with the schema API.

    from tspng.schema.data import Meta as Metadata
    
    print(Metadata(embedded=[Embedded(data="Hello, World!", mime_type="text/plain")]).model_dump_json(ident=2))
    

Application

  1. Install the application.

    python3 -m pip install ".[cli]"
    
  2. Run the application.

    $ tspng extract example.ts.png
    {...}  // Omitted for clarity
    
  3. (Optional) Use the jq utility to obtain specific fields and information from the extracted metadata. For example, to pretty print the output:

    tspng extract example.ts.png | jq .
    

Contributing

  1. Clone this repository.

    git clone https://github.com/Theia-Scientific/tspng && cd tspng
    
  2. Create a virtual environment.

    python3 -m venv .venv
    
  3. Activate the virtual environment.

    source .venv/bin/activate
    
  4. Upgrade pip.

    python3 -m pip install --upgrade pip
    
  5. Install all the dependencies.

    python3 -m pip install -e ".[dev,cli]"
    
  6. Create a local branch.

    git checkout -b feature-awesome-new-feature
    
  7. Modify the code.

  8. Run the tests.

    pytest --color=yes
    
  9. Commit changes to your local branch.

    git add -A && git commit -m "Add new feature"
    
  10. Push your local branch to GitHub to create a Pull Request (PR).

git push origin feature-awesome-new-feature
  1. Create a Pull Request (PR) in GitHub.
  2. Wait for CI to complete.
  3. Add comment to PR that it is ready to review.

License

Acknowledgments

This material is based upon work supported by the U.S. Department of Energy, Office of Nuclear Energy under Award Number DE-SC0021529.

Metadata

Release files for tspng 2.1.0

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

Source distribution (sdist)

Source distribution for tspng 2.1.0
File Size Uploaded Provenance Actions
tspng-2.1.0.tar.gz 728.9 kB With provenance Details for tspng-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 741.9 kB

Release files / tspng-2.1.0.tar.gz

Download URL tspng-2.1.0.tar.gz
Size 728.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ccbfd56b5ec658882b8f0dbda1514c25283e58e6233dedae0bccc21f530260a9
BLAKE2b-256 checksum
How to use checksums
5fad1b82e17c05026aeb4152bec7b662f2cc7dc010d19afe702edef5a8872b96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Release files / tspng-2.1.0-py3-none-any.whl

Download URL tspng-2.1.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c39b4ff90f74ba17bbb4f31e50dc09dbbbbed053fc3d8eb4641a509e0f200e9
BLAKE2b-256 checksum
How to use checksums
8432a6b02b1afaabcd18827bf54679ba681af4f21ea12233999b3c949943dbde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Security for tspng 2.1.0

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 tspng-2.1.0.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 Nov 6, 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