Lightweight Python SDK for ABRomics API
Project description
ABRomics Lightweight Python SDK
A lightweight Python SDK for interacting with the ABRomics API, including resumable file uploads via TUS protocol.
Installation
From PyPI (Recommended)
pip install abromics-library
From Source
git clone https://gitlab.com/ifb-elixirfr/abromics/abromics-library.git
cd abromics-library
pip install -e .
Prerequisites
- Python 3.8+
- ABRomics backend running
- API key with
complete_workflow_uploadscope
Quick Start
1. Get Your API Key
- Go to your ABRomics web interface
- Navigate to the API Keys page
- Create a new API key with scope
complete_workflow_upload - Copy the API key (starts with
abk_)
2. Set Environment Variables (Optional)
export ABROMICS_API_KEY="abk_your_api_key_here"
export ABROMICS_BASE_URL="http://localhost:8000" # Your ABRomics backend URL
Usage
Command Line Interface (CLI)
The ABRomics CLI provides essential commands for managing projects and uploading data:
| Command | Description |
|---|---|
project create |
Create a new project |
complete-upload-workflow |
Complete workflow: TSV processing + file uploads |
Create Project
# Create a new FASTQ project
abromics --api-key "abk_your_api_key_here" --base-url "https://analysis.abromics.fr" project create \
--name "My FASTQ Project" \
--template 1 \
--description "Optional project description"
# Create a new FASTA project
abromics --api-key "abk_your_api_key_here" --base-url "https://analysis.abromics.fr" project create \
--name "My FASTA Project" \
--template 2 \
--description "Optional project description"
Parameters:
--name- Project name (required)--template- Template ID (required): 1 for FASTQ, 2 for FASTA--description- Project description (optional)
Complete Workflow
# One command does everything: validates TSV, creates samples, uploads files
abromics complete-upload-workflow \
--metadata-tsv "/path/to/samples_fastq_projects.tsv" \
--data-dir "/path/to/sequence/files"
What this command does:
- ✅ Auto-detects file types (FASTQ/FASTA)
- ✅ Creates samples from TSV metadata
- ✅ Uploads sequence files to samples
- ✅ Handles multiple projects automatically
Python Library
Basic Usage
from abromics import AbromicsClient
# Initialize client
client = AbromicsClient(
api_key="abk_your_api_key_here",
base_url="http://localhost:8000"
)
# Step 1: Create project (template 1 for FASTQ, 2 for FASTA)
project = client.projects.create(
name="My FASTQ Project",
template=1,
description="Project for FASTQ sequencing data"
)
# Step 2: Complete workflow (auto-detects file types)
result = client.batch.process_tsv_and_upload(
project_id=project.id,
tsv_file="samples_metadata.tsv",
files_directory="/path/to/sequence/files"
)
if result['success']:
print("✅ Workflow completed successfully!")
Advanced Usage
# Individual operations
sample = client.samples.create(
project_id=project.id,
metadata={
"Sample ID": "SAMPLE_001",
"Host species": "Homo sapiens",
"Microorganism scientific name": "Escherichia coli",
"Country": "France"
}
)
# File upload with progress tracking
def progress_callback(message, current, total):
print(f"{message}: {current}/{total}")
uploader = client.upload.create_uploader()
result = uploader.upload_file(
file_path="/path/to/sequence.fastq.gz",
metadata={
"sample_id": str(sample.id),
"file_type": "FASTQ_GZ",
"type": "PAIRED_FORWARD"
},
progress_callback=progress_callback
)
TSV File Format
The TSV file should contain sample metadata with these columns:
Required Fields (marked with *)
Sample ID *- Unique sample identifierStrain ID *- Unique strain identifierHost species *- Host species nameMicroorganism scientific name *- Scientific name of microorganismCountry *- Country where sample was collectedSample type *- Type of sampleSample source *- Source of the sampleInstrument model *- Sequencing instrument modelCollected date *- Date when sample was collectedProject Name *- Name of the project
File Type Fields (one of these)
R1 fastq filename *+R2 fastq filename *- For FASTQ filesFasta filename *- For FASTA files
Optional Fields
Region- Region where sample was collectedPlace- Specific place where sample was collectedTravel countries- Countries visited before collectionAccession number- Public database accession numberSample comment- Additional comments about the sample
Example TSV
Sample ID * Strain ID * R1 fastq filename * R2 fastq filename * Host species * Microorganism scientific name * Country * Project Name *
SAMPLE_001 ST-001 sample_R1.fastq.gz sample_R2.fastq.gz Homo sapiens Escherichia coli France My Project
Examples
CLI Examples
# Create a FASTQ project first
abromics --api-key "abk_your_api_key_here" --base-url "https://analysis.abromics.fr" project create \
--name "My FASTQ Project" \
--template 1 \
--description "Project for FASTQ sequencing data"
# Or create a FASTA project
abromics --api-key "abk_your_api_key_here" --base-url "https://analysis.abromics.fr" project create \
--name "My FASTA Project" \
--template 2 \
--description "Project for FASTA assembly data"
# Complete workflow (TSV + file uploads)
abromics complete-upload-workflow \
--metadata-tsv "examples/samples_fastq_projects.tsv" \
--data-dir "examples/sequence_files/"
Python Examples
# Run the example script
python examples/python_library_example.py
Configuration
Environment Variables
export ABROMICS_API_KEY="abk_your_api_key_here" # Required
export ABROMICS_BASE_URL="http://localhost:8000" # Optional
Priority Order
- Command-line arguments (
--api-key,--base-url) - Environment variables (
ABROMICS_API_KEY,ABROMICS_BASE_URL) - Default values (base URL only)
API Reference
Client
client = AbromicsClient(api_key, base_url, timeout)
Projects
# Create FASTQ project
project = client.projects.create(
name="My FASTQ Project",
template=1, # Template 1 for FASTQ, 2 for FASTA
description="Optional description"
)
# Create FASTA project
project = client.projects.create(
name="My FASTA Project",
template=2, # Template 1 for FASTQ, 2 for FASTA
description="Optional description"
)
# List projects
projects = client.projects.list()
# Get project
project = client.projects.get(project_id)
Samples
# Create sample
sample = client.samples.create(project_id, metadata)
# List samples
samples = client.samples.list(project_id=1)
# Get sample
sample = client.samples.get(sample_id)
Batch Operations
# Complete workflow
result = client.batch.process_tsv_and_upload(
project_id, tsv_file, files_directory
)
Troubleshooting
Common Issues
- API Key Error: Make sure you have a valid API key with the correct scope
- File Not Found: Check that TSV file and data directory paths are correct
- Connection Error: Ensure the ABRomics backend is running on the specified URL
- Permission Error: Verify your API key has the
complete_workflow_uploadscope - Mixed File Types: Don't mix FASTQ and FASTA files in the same directory
Getting Help
- Check the main library documentation above
- Verify your TSV file structure matches the expected format
- Ensure all required fields are present and non-empty
- Check that sequence files exist in the specified directory
Development
# Install in development mode
pip install -e .
# Run tests
pytest
# Run CLI
python -m abromics.cli --help
Publishing
For instructions on how to publish a new version to PyPI, see HowToPublish.md.
License
MIT License
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 abromics_library-1.0.5.tar.gz.
File metadata
- Download URL: abromics_library-1.0.5.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2a573fca2678300230f7f2ca1fdc5b81af08a0ccfb5181276768f7f0c68abf8
|
|
| MD5 |
a150729462407bd039bf0e1fed5c9474
|
|
| BLAKE2b-256 |
e06e352d584a8e22f531d62bac492fc82168eb7dfac6ca946c0527422442ebbe
|
File details
Details for the file abromics_library-1.0.5-py3-none-any.whl.
File metadata
- Download URL: abromics_library-1.0.5-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60c7936175fd90888a698b6217af401f2bc9ad0a2bbad9cd34f98e0f30d51d9d
|
|
| MD5 |
4f946d080f8cc950c3d8ea00697c8bce
|
|
| BLAKE2b-256 |
0eae6f5f0f74e4cb1bae328bc9bb53e962514f5a6fdc84a16428a02229e6df0c
|