SDK to upload and manage chromatographic injections and other data in Elsci Peaksel
Project description
Peaksel SDK (Python)
A library to manage chromatography data in Peaksel: upload raw data, fetch the results of parsing (spectra, traces, peaks, injection info, etc).
pip install elsci-peaksel-sdk
Let's upload a ZIP with raw data and fetch the spectra that Peaksel parsed out:
from peakselsdk.Peaksel import Peaksel
org = "YOUR ORG NAME" # or your username if you want to work with your personal data
auth_header = {"Cookie": "SESSION=YOUR SESSION ID"} # either cookie or Basic Auth
raw_data = "/path/to/zip/with/raw-data.zip"
# Entry point to Peaksel:
peaksel = Peaksel("https://peaksel.elsci.io", org_name=org, default_headers=auth_header)
# Upload & parse, get the ID back:
injection_ids = peaksel.injections().upload(raw_data)
Now we can fetch the results, including chromatograms and spectra:
# Use the ID of the 1st injection to fetch the rest of the info:
j = peaksel.injections().get(injection_ids[0])
for detectorRun in j.detectorRuns:
if not detectorRun.has_spectra():
continue
# Fetch spectra of each detector
spectra = peaksel.blobs().get_spectra(detectorRun.blobs.spectra) # fetch spectra
for spectrum in spectra:
print(f"{spectrum.rt}: {spectrum.x}")
Before running this:
- You need to register at Peaksel Hub, get a private SaaS or install Peaksel on your machines.
- Determine how you want to authenticate (service account or SessionID)
Session ID auth (Cookie)
If you're just playing, you can run the code on behalf of your own account. For this copy the cookie from your browser:
- In Chrome: open Peaksel -> authenticate -> Press F12
- Go to Application tab -> Cookies -> click on the website URL -> copy the Value of the JSESSIONID cookie
Now in the code you set up Peaksel this way:
auth_header = {"Cookie": "SESSION=YOUR SESSION ID"}
Service Accounts auth (Basic Auth)
Service accounts can have their Basic Auth credentials specified in Peaksel configs. This option is available in Private SaaS and on-prem installations. For Peaksel Hub you need to request it (support@elsci.io). If you go with Basic Auth, then in the code you set up auth headers this way:
from peakselsdk.util.api_util import peaksel_basic_auth_header
auth_header = {"Authorization": peaksel_basic_auth_header("your username", "your password")}
Design & Conventions
All the necessary functionality is exposed from peakselsdk.Peaksel class - just use its methods to work with Injections, Batches, Substances (analytes), Peaks, etc.
XxxClientare classes to communicate with the app API, they are created and returned byPeakselentrypoint- Classes like
User,Org,Injectioncapture the actual requests and responses- Fields are
camelCasedto match the JSON structure - The JSON's
idis actually stored ineid(aka entity id) in the classes. Becauseidhas special meaning in Python. - Every
__init__()has**kwargsparam that is ignored. This is needed to simplify parsing of response JSONs, as we always keep the names in the classes and JSONs the same, so when passing those as dict into the constructor, the corresponding fields are set. But it's possible that in Peaksel we add a new param, and this would break dict->DTO conversion as the param will be unknown. So to be forward-compatible, we add**kwargsto capture all the unknown fields.
- Fields are
Working with source code
- Install uv build tool and run:
uv venv && uv sync && uv build - In PyCharm mark
srcas Sources Root andtestas Test Sources Root - To run the tests
./test.sh
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file elsci_peaksel_sdk-1.1.0.tar.gz.
File metadata
- Download URL: elsci_peaksel_sdk-1.1.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9fa16115d8c155b23b6e7ed6d430a847835fc85bbba9703d22f1982ee04b1be
|
|
| MD5 |
05710d6780af715564750decaa05b428
|
|
| BLAKE2b-256 |
65eebd1749730e48fd185eb00343db000449e98d91a81764fe2e65ba193c7c4c
|
Provenance
The following attestation bundles were made for elsci_peaksel_sdk-1.1.0.tar.gz:
Publisher:
python-publish.yml on elsci-io/peaksel-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
elsci_peaksel_sdk-1.1.0.tar.gz -
Subject digest:
f9fa16115d8c155b23b6e7ed6d430a847835fc85bbba9703d22f1982ee04b1be - Sigstore transparency entry: 159575687
- Sigstore integration time:
-
Permalink:
elsci-io/peaksel-sdk@074b38b7a66677f11ee98339263afb59ac30393c -
Branch / Tag:
refs/heads/master - Owner: https://github.com/elsci-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@074b38b7a66677f11ee98339263afb59ac30393c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file elsci_peaksel_sdk-1.1.0-py3-none-any.whl.
File metadata
- Download URL: elsci_peaksel_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6e9ddf954ff687b382d7d5328730498fc39ebc7b09dafb7b8ae05c26d923934
|
|
| MD5 |
67c8588981ed8c037c2ff0779816aac6
|
|
| BLAKE2b-256 |
142c6ae6ca17343af2c4d5233a554cf19aa75095c0581d859f5265ec0494d3f8
|
Provenance
The following attestation bundles were made for elsci_peaksel_sdk-1.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on elsci-io/peaksel-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
elsci_peaksel_sdk-1.1.0-py3-none-any.whl -
Subject digest:
d6e9ddf954ff687b382d7d5328730498fc39ebc7b09dafb7b8ae05c26d923934 - Sigstore transparency entry: 159575688
- Sigstore integration time:
-
Permalink:
elsci-io/peaksel-sdk@074b38b7a66677f11ee98339263afb59ac30393c -
Branch / Tag:
refs/heads/master - Owner: https://github.com/elsci-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@074b38b7a66677f11ee98339263afb59ac30393c -
Trigger Event:
workflow_dispatch
-
Statement type: