Skip to main content

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).

Print some spectra info in console:

from peakselsdk.Peaksel import Peaksel

org = "YOUR ORG NAME"  # or your username if you want to work with your personal data
auth_header = {"Cookie": "JSESSIONID=YOUR SESSION ID"}  # either cookie or Basic Auth
raw_data = "/path/to/zip/with/raw-data.zip"

base_url = "https://peaksel.elsci.io"
# The actual code to upload raw data, and retrieve all the parsed info:
peaksel = Peaksel(base_url, org_name=org, default_headers=auth_header)
injection_ids = peaksel.injections().upload(raw_data)  # upload your sample
j = peaksel.injections().get(injection_ids[0])  # fetch Injection info
for detectorRun in j.detectorRuns:
    spectra = peaksel.blobs().get_spectra(detectorRun.blobs.spectra)  # fetch spectra
    for spectrum in spectra:
        print(f"{spectrum.rt}: {spectrum.x}")

Before running this:

  1. You need to register at Peaksel Hub, get a private SaaS or install Peaksel on your machines.
  2. Determine how you want to authenticate (service account or SessionID)

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 explicitly (support@elsci.io). If this option is chosen, 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")}

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:

  1. In Chrome: open Peaksel -> authenticate -> Press F12
  2. 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": "JSESSIONID=YOUR SESSION ID"}

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.

  • XxxClient are classes to communicate with the app API, they are created and returned by Peaksel entrypoint
  • Classes like User, Org, Injection capture the actual requests and responses
    • Fields are camelCased to match the JSON structure
    • The JSON's id is actually stored in eid (aka entity id) in the classes. Because id has special meaning in Python.
    • Every __init__() has **kwargs param 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 **kwargs to capture all the unknown fields.

Working with source code

  1. Install uv build tool and run uv build
  2. In PyCharm mark src as Sources Root and test as Test Sources Root
  3. 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

elsci_peaksel_sdk-0.0.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

elsci_peaksel_sdk-0.0.1-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file elsci_peaksel_sdk-0.0.1.tar.gz.

File metadata

  • Download URL: elsci_peaksel_sdk-0.0.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for elsci_peaksel_sdk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c852733f49482cb15f7a6252b7932a7b5f9fa14fdc13a02ab0ad87571611da7a
MD5 856e5afe2239cd39c7bfc0f8f2bf99f4
BLAKE2b-256 2b90889f4087ebfbc46744c7b09688c100590fd7cd0c4e5049fc279c9b1f2528

See more details on using hashes here.

Provenance

The following attestation bundles were made for elsci_peaksel_sdk-0.0.1.tar.gz:

Publisher: python-publish.yml on elsci-io/peaksel-sdk

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

File details

Details for the file elsci_peaksel_sdk-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for elsci_peaksel_sdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02532019fee706556dcbfc1f04a33d6bfaed56b887c8933216625772c02981bd
MD5 68a9dc2bca3dd023d034bdce9d5bca40
BLAKE2b-256 f03b01147a3812c8386fa774706ddb7640405bd1c0290bffa793566624b2ca1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for elsci_peaksel_sdk-0.0.1-py3-none-any.whl:

Publisher: python-publish.yml on elsci-io/peaksel-sdk

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