Skip to main content

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

CI Google Colab codecov

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.0.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.0.0
File Size Uploaded
tspng-2.0.0.tar.gz 727.8 kB Details

Built distribution (wheel)

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

Total release size: 740.7 kB

Release files / tspng-2.0.0.tar.gz

Download URL tspng-2.0.0.tar.gz
Size 727.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5d0ebf4ffd7867d90bb19bd737c1ec9a1a285c750f9ba212f131f3eee5281aa8
BLAKE2b-256 checksum
How to use checksums
a0db4eafbaedf18276feaf0874c92fb9e91c3374f856ba8259eb179f264d9474
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

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

Download URL tspng-2.0.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74bd409f7a352a62cf26536dad9a762af23d7ae3e8912cf9c3a6e994dd316db9
BLAKE2b-256 checksum
How to use checksums
79d87d1e7f29cde5b3407b472c263f770e602c03a91d976b90409e5cf4794ba3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.1

2 release files

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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