Skip to main content

Python wrapper for Benchling API with common functions used at MGTX DSC

Project description

mgtx-benchling-wrapper

A wrapper of the Benchling API SDK with common functions and workflows used at MGTX DSC.

Installation 🚀

You can install this package using:

pip install mgtx-benchling-wrapper

Quickstart 🚩

After creating an app on your Benchling tenant, create a config.yaml file in your repo. The following is an example of the contents of a config.yaml

Note: You might want to keep the app client secret separated from your main code.

BenchlingCredentials:
  benchling_url: 'https://mytenant.benchling.com'
  benchling_access_token: 'https://mytenant.benchling.com/api/v2/token'
  app_client_id: 'your-app-client-id'
  app_client_secret: 'your-app-client-secret'
AssaySchema:
  schema_id: "schema_api_id"
Project:
  project_id: "project_api_id"

The following is an example of the use of the assay_results_ingestion workflow.

import yaml
from mgtx_benchling_wrapper import BenchlingContext
from mgtx_benchling_wrapper import BenchlingWrapperFacade
from mgtx_benchling_wrapper import AssayResultIngestionWorkflow
from mgtx_benchling_wrapper.utils.logger import get_logger

logger = get_logger(__name__,
                        file_log_level='DEBUG',
                        console_log_level='INFO', )

def config():
    with open("tests/config/test_config.yml") as f:
        return yaml.safe_load(f)

#create the benchling context        
ctx = BenchlingContext(
        base_url=config()['BenchlingCredentials']['benchling_url'],
        client_id=config()['BenchlingCredentials']['app_client_id'],
        client_secret=config()['BenchlingCredentials']['app_client_secret'],
        token_url=config()['BenchlingCredentials']['benchling_access_token'],
    )    

#initialize the wrapper
wrapper = BenchlingWrapperFacade(ctx.benchling())

#retrieve assay_schema_id
schema_id = config()['AssaySchema']['schema_id']

#retrieve project_id
project_id = config()['Project']['project_id']

#initiate results ingestion workflow
results_ingestion = AssayResultIngestionWorkflow(wrapper)

#ingest results on benchling
list_missing_entities = results_ingestion.assay_results_ingestion(
        [dataframe_to_ingest],
        schema_id,
        project_id,
        unique_identifiers =['assay_run_id', 'sample_id']
        )       

Another example is accessing a Benchling assay results schema metadata.

#run the following after initializing the wrapper

from mgtx_benchling_wrapper import SchemaHandler

schema_handler = SchemaHandler(wrapper)

schema_definition = schema_handler.build_schema_definition(schema_id, 'assay_results_schema')

Another example is using a method from the wrapper directly to build your own workflow.

#run the following after initializing the wrapper

list_custom_entities = wrapper.custom_entities.get_by_names(['your-entity-1', 'your-entity-2'])

for custom_entity in list_custom_entities:
    name = wrapper.custom_entities.name()
    print(f"the name of the custom entity {custom_entity} is {name}.")

To release and publish run the following on gitBash to initialize the GitHub Action for publishing the package.

git tag v0.1.#
git push origin v0.1.#

Logs are by default enabled for developer use on the console. To save logs, an environment variable is needed. Create the environment variable on your repo in a .env file as such, and then make sure to load it.

APP_DEBUG_LOGS=1

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

mgtx_benchling_wrapper-0.1.7.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

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

mgtx_benchling_wrapper-0.1.7-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

Details for the file mgtx_benchling_wrapper-0.1.7.tar.gz.

File metadata

  • Download URL: mgtx_benchling_wrapper-0.1.7.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mgtx_benchling_wrapper-0.1.7.tar.gz
Algorithm Hash digest
SHA256 aac6211478f5d3d9c625227c9f77864b0856d0229754ea777211818422b17d5e
MD5 6c4a85b236d1dda4b7c5db6da44ae3c5
BLAKE2b-256 61bdeb43887fc170cc2b7b3a24ab1cb00c3b39cdb3b97fd4d5aae244dd6d0f1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgtx_benchling_wrapper-0.1.7.tar.gz:

Publisher: publish.yml on MGTX-Data-Science/mgtx-benchling-wrapper

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

File details

Details for the file mgtx_benchling_wrapper-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for mgtx_benchling_wrapper-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 da089963d0e2a28137c2629ddb8673ce654c643c6aeb2b1b484f43f348f3e3ac
MD5 17c88d0130cd50824969db75c84a46b6
BLAKE2b-256 09f05f9f9e659e7d5bb1bf491de2aec60d4c8ef0a41759f8cb9fd1658325c388

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgtx_benchling_wrapper-0.1.7-py3-none-any.whl:

Publisher: publish.yml on MGTX-Data-Science/mgtx-benchling-wrapper

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