A Pythonic client library for the SampleTracker SaaS API
Project description
HSE SampleTracker Client
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_dictconstructors - Comprehensive Exceptions - Clear error hierarchy for different failure modes
- Environment Configuration - Support for
.envfiles 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 IDsample_id: User-facing sample identifiername: Sample namedescription: Optional descriptionowner_id: Owner's user IDcreated_at: Creation timestampupdated_at: Last update timestampstep_count: Number of processing stepsobservation_count: Number of observations
Sample
Detailed model with full history:
- All fields from
SampleListItem, plus: owner_email: Email of the ownerhistory: List ofStepEventandObservationEventstats:SampleStatswith 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
- Documentation: https://github.com/Alexander Schramm/sampletracker#readme
- Issues: https://github.com/Alexander Schramm/sampletracker/issues
- Source: https://github.com/Alexander Schramm/sampletracker
- PyPI: https://pypi.org/project/hse-sampletracker-client
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80a3800b62591909daad5573905f7be6f88c70e9f9d34159a0cd2737a13baaa5
|
|
| MD5 |
0f2f301e8151dc59e1dd0f16ee99fb86
|
|
| BLAKE2b-256 |
fa77510c067993a5f07dab89c3b5e4665ae1e7481da431dad28427007b1e8580
|
File details
Details for the file hse_sampletracker_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hse_sampletracker_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bed02abec36b119146aef37f00d88b7e07fd2f60a94b5084d4dfaaba6e7d3f13
|
|
| MD5 |
928f6cebfbcc2dec7f483ced3d3e9305
|
|
| BLAKE2b-256 |
57e0ca7d664a4caa65afa4fe6545f0dc301ee1eadecc0b976d4bb8f7a177b1de
|