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 HSE 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 (Copy) |     3 |            2

View sample details:

$ sampletracker view sample-001
Sample Details:
  ID:          1
  Sample ID:   sample-001
  Name:        test batch
  Description: mein erster test
  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.

Links

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.1.tar.gz (12.3 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.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hse_sampletracker_client-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 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.1.tar.gz
Algorithm Hash digest
SHA256 80a3800b62591909daad5573905f7be6f88c70e9f9d34159a0cd2737a13baaa5
MD5 0f2f301e8151dc59e1dd0f16ee99fb86
BLAKE2b-256 fa77510c067993a5f07dab89c3b5e4665ae1e7481da431dad28427007b1e8580

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hse_sampletracker_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bed02abec36b119146aef37f00d88b7e07fd2f60a94b5084d4dfaaba6e7d3f13
MD5 928f6cebfbcc2dec7f483ced3d3e9305
BLAKE2b-256 57e0ca7d664a4caa65afa4fe6545f0dc301ee1eadecc0b976d4bb8f7a177b1de

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