Skip to main content

labguru-api-client

Python api client for accessing the Labguru Electronic Lab Notebook.

This package contains two main groups of code:

  1. Generated code from the OpenAPI spec for the Labguru API, using openapi-python-client. This code is in the labguru_api_client directory.
  2. Wrapper functions around the generated code to make it easier to use. This part is still in development.

Installing

You can install this package using pip:

pip install labguru-api-client

Usage (wrapper functions)

Wrapper functions are under active development and are expected to change. For now, a few experiment-related fucntions have been defined.

from labguru_wrapper.labguru_api import LabguruAPI

# define env vars in ~/.labguru.env
# LABGURU_API_KEY is required
# LABGURU_BASE_URL is optional
labguru = LabguruAPI()

exp1_1 = labguru.get_experiment(1)
# returned object will be a dict/json representation of the experiment
print(exp1_1["title"])

exp1_updated = labguru.update_experiment(1, {"title": "My new title"})
assert labguru.get_experiment(1)["title"] == "My new title"

Usage (generated code)

Create a client and make an example request to get an experiment by id. Your Labguru API key should be stored in an environment variable called LABGURU_API_KEY. Extracing information from the response can be done by parsing the response.content attribute. The Labguru openAPI spec did not include a response model for their endpoints, so response.parsed will be None.

import json
from labguru_api_client import Client
from labguru_api_client.api.experiments import get_api_v1_experiments_id

client = Client(base_url="https://my.labguru.com/")
exp_1 = get_api_v1_experiments_id.sync_detailed(client=client, token=os.getenv("LABGURU_API_KEY"), id=1)
if exp_1.status_code == 200:
    print(json.loads(exp_1.content)["title"])

To update or create an experiment, use the generated models to create a body for the request.

import json
from labguru_api_client import Client
from labguru_api_client.api.experiments import put_api_v1_experiments_id
from labguru_api_client.models import UpdateExperimentItem, UpdateExperiment

updated_experiment_item = UpdateExperimentItem.from_dict({
    "title": "My new title"
})
updated_experiment = UpdateExperiment(token=os.getenv("LABGURU_API_KEY"), item=updated_experiment_item)

exp_1_put = put_api_v1_experiments_id.sync_detailed(client=client, id=1, body=updated_experiment)
exp_1_updated = get_api_v1_experiments_id.sync_detailed(client=client, token=os.getenv("LABGURU_API_KEY"), id=1)
if exp_1_put.status_code == 200 and exp_1_updated.status_code == 200:
    assert json.loads(exp_1_updated.content)["title"] == "My new title"

Things to know:

  1. Every path/method combo becomes a Python module with four functions:

    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Request, optionally with parsed set if the request was successful.
    3. asyncio: Like sync but async instead of blocking
    4. asyncio_detailed: Like sync_detailed but async instead of blocking
  2. All path/query params, and bodies become method arguments.

  3. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)

  4. Any endpoint which did not have a tag will be in labguru_api_client.api.default

Advanced customizations

There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client or httpx.AsyncClient (depending on your use-case):

from labguru_api_client import Client

def log_request(request):
    print(f"Request event hook: {request.method} {request.url} - Waiting for response")

def log_response(response):
    request = response.request
    print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")

client = Client(
    base_url="https://my.labguru.com",
    httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)

# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()

You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):

import httpx
from labguru_api_client import Client

client = Client(
    base_url="https://my.labguru.com",
)
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
client.set_httpx_client(httpx.Client(base_url="https://my.labguru.com", proxies="http://localhost:8030"))

Metadata

Release files for labguru-api-client 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for labguru-api-client 0.1.3
File Size Uploaded Provenance Actions
labguru_api_client-0.1.3.tar.gz 118.2 kB Without provenance Details for labguru_api_client-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for labguru-api-client 0.1.3
File Interpreter ABI Platform Actions
labguru_api_client-0.1.3-py3-none-any.whl Python 3 none any Details for labguru_api_client-0.1.3-py3-none-any.whl

Total release size: 738.5 kB

Release files / labguru_api_client-0.1.3.tar.gz

Download URL labguru_api_client-0.1.3.tar.gz
Size 118.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d7c3765bce3ad231006c24dca9b98defe877e4d4b2c29f4f07e2c414bc6a4654
BLAKE2b-256 checksum
How to use checksums
727bb005a778edb5328d820d8fe6b821bbd86652c11443960a3bd9b344eac236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-oem

Release files / labguru_api_client-0.1.3-py3-none-any.whl

Download URL labguru_api_client-0.1.3-py3-none-any.whl
Size 620.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12ec64e6b358caed04393b383e520947cdd61d58731aef325bba8f231d8079cd
BLAKE2b-256 checksum
How to use checksums
a6041facc4030775e2b0ea7663dff96ef4dfec7a080c8335c7cda9759d83521e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-oem

Security for labguru-api-client 0.1.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page