PtyLab.py: Unified Ptychography Toolbox
Getting Started | Installation | Development | Documentation
PtyLab is an inverse modeling toolbox for Conventional (CP) and Fourier (FP) ptychography in a unified framework. For more information please check the paper.
Key Features
- Classic engines: ePIE, mPIE, mqNewton, qNewton
- Advanced corrections: position correction (pcPIE), defocus correction (zPIE), angle correction (aPIE), orthogonal probe relaxation (OPR)
- Multi-modal: multi-slice, multi-wavelength, mixed-state object and probe
- Multiple propagators: Fraunhofer, Fresnel, Angular Spectrum (ASP), scaled ASP, polychromatic variants
- GPU acceleration: same code runs on CPU and GPU
The reconstructed output is a 6D array of shape (nlambda, nosm, npsm, nslice, No, No):
| Dim | Meaning |
|---|---|
nlambda |
wavelengths |
nosm |
object state mixture |
npsm |
probe state mixture |
nslice |
depth slices |
No |
output frame size |
Getting started
Try the demo in Google Colab:
For more use cases, start with the tutorials in our documentation, then see the example_scripts directory.
Installation
Install from PyPI within your virtual environment:
pip install ptylab
For much faster installs, we recommend uv: uv pip install ptylab
This package uses cupy to utilize GPU for faster reconstruction. To enable GPU support:
pip install "ptylab[gpu]"
You can check if GPU is detected with ptylab check gpu.
For the latest unreleased changes on main:
pip install git+https://github.com/PtyLab/PtyLab.py.git
Development
Clone the repo and install dev and gpu dependencies with uv:
git clone git@github.com:PtyLab/PtyLab.py.git
cd PtyLab.py
uv sync --extra dev,gpu # remove the GPU flag if you are on CPU
This creates a .venv virtual environment in the project root. Select this environment from your IDE.
Add tests for new implementations and run the suite:
uv run pytest tests
Documentation
Any documentation changes would be deployed automatically after a PR merges main. However, please verify locally first with
uv run --extra docs mkdocs serve
Citation
If you use this package, please cite:
@article{Loetgering:23,
author = {Lars Loetgering and Mengqi Du and Dirk Boonzajer Flaes and Tomas Aidukas and Felix Wechsler and Daniel S. Penagos Molina and Max Rose and Antonios Pelekanidis and Wilhelm Eschen and J\"{u}rgen Hess and Thomas Wilhein and Rainer Heintzmann and Jan Rothhardt and Stefan Witte},
journal = {Opt. Express},
number = {9},
pages = {13763--13797},
publisher = {Optica Publishing Group},
title = {PtyLab.m/py/jl: a cross-platform, open-source inverse modeling toolbox for conventional and Fourier ptychography},
volume = {31},
month = {Apr},
year = {2023},
doi = {10.1364/OE.485370},
}
Metadata
Release files for ptylab 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ptylab-0.3.2.tar.gz | 98.5 kB | With provenance | Details for ptylab-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ptylab-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for ptylab-0.3.2-py3-none-any.whl |
Total release size: 226.7 kB
Release files / ptylab-0.3.2.tar.gz
| Download URL | ptylab-0.3.2.tar.gz |
|---|---|
| Size | 98.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
008cf736c20d477ab54087ce3f9bceb7e55868b60c97ea4b00d9b3a0b5b3b4ea
|
|
BLAKE2b-256 checksum How to use checksums |
8bc7ceeea2acafbab77a0bf6b4d72c0ea9fa12b142cc53127efc82e86f360a97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.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 / ptylab-0.3.2-py3-none-any.whl
| Download URL | ptylab-0.3.2-py3-none-any.whl |
|---|---|
| Size | 128.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
897c0b957ef994a7b2fa4d5f5630355892b529758eabca9a5fc4b24a9ba0c2f8
|
|
BLAKE2b-256 checksum How to use checksums |
68957e27852b61410402141d55dd4f8a4ba3da1e9e72547cce27d56bf933103d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.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 logSecurity for ptylab 0.3.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.
Attestation for ptylab-0.3.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 Sep 23, 2026.
Transparency logA 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.