tspng: A Python package for Computer Vision and Machine Learning metadata manipulation
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
-
Create a virtual environment.
python3 -m venv .venv
-
Activate the virtual environment.
source .venv/bin/activate
-
Install tspng.
python3 -m pip install tspng
-
Create a
png_dump.pyscript 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_FILEis replaced, in quotes, with the path to a.ts.pngfile on disk. -
Run the
png_dump.pyscript,$ 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.
-
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")
-
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
-
Install the application.
python3 -m pip install ".[cli]"
-
Run the application.
$ tspng extract example.ts.png {...} // Omitted for clarity
-
(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
-
Clone this repository.
git clone https://github.com/Theia-Scientific/tspng && cd tspng
-
Create a virtual environment.
python3 -m venv .venv
-
Activate the virtual environment.
source .venv/bin/activate
-
Upgrade
pip.python3 -m pip install --upgrade pip
-
Install all the dependencies.
python3 -m pip install -e ".[dev,cli]"
-
Create a local branch.
git checkout -b feature-awesome-new-feature
-
Modify the code.
-
Run the tests.
pytest --color=yes
-
Commit changes to your local branch.
git add -A && git commit -m "Add new feature"
-
Push your local branch to GitHub to create a Pull Request (PR).
git push origin feature-awesome-new-feature
- Create a Pull Request (PR) in GitHub.
- Wait for CI to complete.
- 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tspng-2.0.1.tar.gz | 728.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tspng-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 741.8 kB
Release files / tspng-2.0.1.tar.gz
| Download URL | tspng-2.0.1.tar.gz |
|---|---|
| Size | 728.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28c5e0c8a50a024e8d1cba378d6da07f75d036840a550b49046269265a911442
|
|
BLAKE2b-256 checksum How to use checksums |
8efca97b80d507a0eff9632eb95985eb9b012efc401aefc23982ba26a9fc7c37
|
| 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 23, 2026.
Transparency logRelease files / tspng-2.0.1-py3-none-any.whl
| Download URL | tspng-2.0.1-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8e5b018c2a568867418dd2cd77b79b4fb0a39d25fbbd35b975f7ecd2e8f2ffb
|
|
BLAKE2b-256 checksum How to use checksums |
2b622fc691dda758c2db4d8b3117e02e0a83212e5942bb09a642003502b49558
|
| 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 23, 2026.
Transparency log