Skip to main content

Python API implementation of PSI plantscreen API

Project description

PSI Plantscreen API implementation

PyPI version


Photon System Instruments (PSI) delivers equipment across the globe. Their cimatecells are controlled with plantscreen software, which comes with an API. Experience taught us, this API is a bit tricky to implement. We believe it's a waste of time if everyone has to figure out how to implement this API and test it. Therefore, we created the swagger file and a simple python wrapper to integrate the endpoints of the plantscreen API. Additionally the model classes are enriched with properties and functions to access linked models to make usage easier.

Unfortunately, we were not able to test the 3D scanner and MSC endpoints as the facilities are not equipped with these systems.

Installation

Unfortunately currently only available on test pypi, installable with: python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple psi-plantscreen

pip install psi-plantscreen

Example implementation

Uses a .env file with the following fields:

HOST=http://<ip-address>:<poort>

The environment files have one additional depency: pip install python-dotenv Examples:

Contributing

We welcome contributions! If you encounter bugs, have feature requests, or want to suggest improvements, please create an issue and provide a clear description.

Setting up a Development Environment

Tested with python 3.10, 3.11, 3.12 and 3.13.

  1. Create a virtual environment (venv):
    python -m venv .venv
    
  2. Activate the venv:
    • On Windows:
      .venv\Scripts\activate
      
    • On macOS/Linux:
      source .venv/bin/activate
      
  3. Install the package with build and test dependencies:
    pip install .[build, test]
    

Updating the OpenAPI specification file

The API is automatically generated from the OpenAPI specification file with the openapi generator cli. The workflows automatically build the client and copy the files to the right folders.

Not all endpoints use the default openAPI implementation. for example, file endpoint use a socket (data stream) to download the files. It's unclear how to implement streams in the swagger file. Those endspoints are also called without the returntype prefeix: '/json' , which means they require a different url. Luckily, openAPi suports the use of mustache template files to customize the generation process. They are used to add the following functionality:

  • Custom classes and functionality:
    • file_api_method.mustache: file api endpoint used a bytestream instead of an HTTP call to stream the file content.
    • partial_link_property.mustache: adds a lazy-loaded property for a direct 1:1 link. When you access it, it calls the related API once, stores the result on the model, and returns the linked object.
    • partial_implicit_link.mustache: adds a similar lazy-loaded property, but for links defined at the model level through vendor extensions rather than on a single field. It fetches the related model automatically from the source value on the current object.
    • partial_rel_function.mustache: adds a method for relationship lookups that may need extra parameters and may return one object or a list. Unlike the property-based links, this is an explicit function call for more flexible related-data queries.
  • __init__api.mustache: Allow single value arguments to be passed for parameters accepting a list of values.
  • api_doc.mustache: Updated the links to other files.
  • api.mustache: Contains the logic to parse a list of ints for the experiment_id, owner_id and profile_id calls and implements the file_api call.
  • configuration.mustache: Switches the datetime format to the one passed in the generation command.
  • model_doc.mustache: Updated to describe relations and links to other files. It is combined with: generate_docs.py which genertes documentation for the 'not auto generated' code and lists all models and API endpoints.
  • model_generic.mustache: adds the custom links and relations mentioned above. Removes the datetime parsing. Additionally a change was added to allow API calls to return 'None', with special logic for 'JsonMscCalibrationLightResult' and 'JsonMscCalibrationLightByIDResult' and the combination of 'JsonProbeResult' and 'JsonProbeByIDResult'.

More information about mustache templating can be found here: mustache templates Additionally, a clean set of templates can be generated with the generate_mustache_templates.yml workflow. This is ideal to check what was edited or to add new changes.

After this some postprocessing scripts are executed to make it work:

  1. run pip install . and then use generate_complete_api_client.py to create a single file with all the api calls for convenience.
  2. Copy xml_decoder.py to the plantscreen folder
  3. Update the documentation generate_docs.py and update_docs.py
  4. Run update_init.py to make the complete_api_client and xml classes available in the package.

Documentation

Build with mkdocs-material

Note, the docs pages will unfortunately not be available untill this repo is made public.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psi_plantscreen-0.2.5.dev0.tar.gz (322.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psi_plantscreen-0.2.5.dev0-py3-none-any.whl (485.4 kB view details)

Uploaded Python 3

File details

Details for the file psi_plantscreen-0.2.5.dev0.tar.gz.

File metadata

  • Download URL: psi_plantscreen-0.2.5.dev0.tar.gz
  • Upload date:
  • Size: 322.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for psi_plantscreen-0.2.5.dev0.tar.gz
Algorithm Hash digest
SHA256 976d222883cf00d9e30dccc84216f78005b6b7117e5e371f33bf6255cda9f7d3
MD5 51e7e0c26f6cd378bb0764af92d23776
BLAKE2b-256 326095e56c93546d9f9793217a9c81dc004be2a35532827846d58f7a26f7e4a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for psi_plantscreen-0.2.5.dev0.tar.gz:

Publisher: release.yml on NPEC-NL/PSI-plantscreen-API

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file psi_plantscreen-0.2.5.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for psi_plantscreen-0.2.5.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea4e71a1d3283c94b845bfa0e41d363a92a12d99e7e48ab8b49ca2478b1446bb
MD5 9aed0c834aad354003e371c03acce96f
BLAKE2b-256 f9555f9637ea071bdd476e538bfbae29f7e575549c3be1b46c9804fbbd003a52

See more details on using hashes here.

Provenance

The following attestation bundles were made for psi_plantscreen-0.2.5.dev0-py3-none-any.whl:

Publisher: release.yml on NPEC-NL/PSI-plantscreen-API

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page