Skip to main content

A Pythonic client library for the SampleTracker SaaS API

Project description

HSE SampleTracker Client

PyPI - Version PyPI - Python Version License

A Pythonic client library for the SampleTracker API - manage laboratory samples, processing steps, and observations with ease.

Features

  • Synchronous API Client - Simple, blocking HTTP client using httpx
  • Type Hints Throughout - Fully typed for better IDE support and code safety
  • Command-Line Interface - Interactive CLI for quick sample management
  • Pydantic-like Models - Dataclass-based models with from_dict constructors
  • Comprehensive Exceptions - Clear error hierarchy for different failure modes
  • Environment Configuration - Support for .env files and environment variables
  • Pagination Support - Built-in cursor-based pagination for listing samples

Installation

pip install hse-sampletracker-client

Quick Start

Using the Python API

from sampletracker import SampleTrackerClient

# Create a client
client = SampleTrackerClient(
    api_key="your-api-key",
    base_url="https://your-instance.com/api/v1"
)

# List samples
samples = client.list_samples(limit=10)
for sample in samples:
    print(f"{sample.sample_id}: {sample.name}")

# Get detailed sample information
sample = client.load_sample("SAMPLE-123")
print(f"Description: {sample.description}")
print(f"Steps: {sample.stats.step_count}")
print(f"Observations: {sample.stats.observation_count}")

# View history
for event in sample.history:
    if hasattr(event, 'name'):  # StepEvent
        print(f"Step: {event.name}")
    else:  # ObservationEvent
        print(f"Observation: {event.content}")

Using the CLI

Set up your environment:

# Option 1: Environment variables
export SAMPLETRACKER_API_KEY="your-api-key"
export SAMPLETRACKER_BASE_URL="https://your-instance.com/api/v1"

# Option 2: Create a .env file
echo "SAMPLETRACKER_API_KEY=your-api-key" > .env
echo "SAMPLETRACKER_BASE_URL=https://your-instance.com/api/v1" >> .env

List samples:

$ sampletracker list --limit 5
    ID |       Sample ID |                           Name | Steps | Observations
--------------------------------------------------------------------------------
     1 |      sample-001 |                     test batch |     3 |            2
     2 |        M315SO23 |                     test batch |     4 |            1

View sample details:

$ sampletracker view sample-001
Sample Details:
  ID:          1
  Sample ID:   sample-001
  Name:        test batch
  Description: my first batch
  Owner ID:    2
  Owner Email: admin@example.com
  Created:     2026-04-25 13:14:13.126000+00:00
  Updated:     2026-04-25 13:14:13.126000+00:00
  Steps:       2
  Observations: 2

  History:
    [Step] Backen
      Performed: 2026-04-25 13:20:00+00:00
      Parameters:
        - Temperatur: 210 °C
    [Observation] Das Ding ist heiß
      Created: 2026-04-25 13:21:06.172000+00:00

Configuration

Environment Variables

Variable Description Required
SAMPLETRACKER_API_KEY Your API key Yes
SAMPLETRACKER_BASE_URL API base URL No (defaults to official SaaS)

.env File

Create a .env file in your project root:

SAMPLETRACKER_API_KEY=your-api-key
SAMPLETRACKER_BASE_URL=https://your-instance.com/api/v1

The CLI automatically loads variables from .env files in the current or parent directories.

API Reference

SampleTrackerClient

The main client class for interacting with the API.

client = SampleTrackerClient(
    api_key: str,           # Your API key
    base_url: str | None,   # Optional base URL
    timeout: float | None   # Optional timeout (default: 30s)
)

Methods

list_samples(limit: int = 10, after_id: int | None = None) -> list[SampleListItem]

List samples with pagination support.

  • limit: Number of samples to return (max: 100)
  • after_id: Cursor for pagination (returns samples with ID > after_id)

load_sample(sample_id: str) -> Sample | None

Get detailed information about a specific sample, including history.

Returns None if the sample doesn't exist.

Models

SampleListItem

Lightweight model for list responses:

  • id: Internal database ID
  • sample_id: User-facing sample identifier
  • name: Sample name
  • description: Optional description
  • owner_id: Owner's user ID
  • created_at: Creation timestamp
  • updated_at: Last update timestamp
  • step_count: Number of processing steps
  • observation_count: Number of observations

Sample

Detailed model with full history:

  • All fields from SampleListItem, plus:
  • owner_email: Email of the owner
  • history: List of StepEvent and ObservationEvent
  • stats: SampleStats with aggregated counts

Exceptions

All exceptions inherit from SampleTrackerError:

  • SampleTrackerAuthError - Authentication failed (401)
  • SampleTrackerNotFoundError - Resource not found (404)
  • SampleTrackerValidationError - Request validation failed (422)
  • SampleTrackerRateLimitError - Rate limit exceeded (429)
  • SampleTrackerAPIError - Other API errors

Supported Python Versions

  • Python 3.10+
  • Python 3.11+
  • Python 3.12+
  • Python 3.13+
  • Python 3.14+
  • PyPy 3.10+

License

hse-sampletracker-client is distributed under the terms of the MIT license.

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

hse_sampletracker_client-0.1.2.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

hse_sampletracker_client-0.1.2-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file hse_sampletracker_client-0.1.2.tar.gz.

File metadata

  • Download URL: hse_sampletracker_client-0.1.2.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1

File hashes

Hashes for hse_sampletracker_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4bdb9bb49323a8e75e8a6cfd61266d04f2b75f5c48b5c59a817e049c401214d5
MD5 42feaec54d68d822541f4556779b1f44
BLAKE2b-256 0706751a004dce4fcc594248744923a80abbf2accb1d980cbcdec42da6ab3d5e

See more details on using hashes here.

File details

Details for the file hse_sampletracker_client-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for hse_sampletracker_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd20a9a9488a1101b6d017c7f6480957b6658050a40344e6cc4d1d77e4d6bb86
MD5 6ea97be16529ffca59f212a75874bd54
BLAKE2b-256 ed5c6fe55d17ed0a4bcf19c39453c5c1a03c100837daa8d3036c75239062070a

See more details on using hashes here.

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