Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
# TableScanner Environment Variables
# Copy this file to .env and fill in your actual values

# =============================================================================
# AUTHENTICATION
# =============================================================================
# KBase Service Authentication Token
KB_SERVICE_AUTH_TOKEN=your_kbase_token_here
# For development testing, use your personal token from KBase
KB_SERVICE_AUTH_TOKEN=YOUR_KBASE_TOKEN_HERE

# Cache directory for storing downloaded files and SQLite databases
# =============================================================================
# CACHE SETTINGS
# =============================================================================
# Cache directory for storing downloaded SQLite databases
CACHE_DIR=/tmp/tablescanner_cache

# Maximum age of cached files in hours (default: 24)
CACHE_MAX_AGE_HOURS=24

# =============================================================================
# KBASE SERVICE URLS
# =============================================================================
# KBase Workspace Service URL
WORKSPACE_URL=https://appdev.kbase.us/services/ws

# Base URL for KBase services
KBASE_ENDPOINT=https://appdev.kbase.us/services

# KBase Blobstore/Shock service URL
BLOBSTORE_URL=https://appdev.kbase.us/services/shock-api

# =============================================================================
# APPLICATION SETTINGS
# =============================================================================
# Enable debug mode (true/false)
DEBUG=false

# =============================================================================
# TEST DATA (AppDev)
# =============================================================================
# Test BERDLTable object: 76990/ADP1Test
# Test pangenome: GCF_000368685.1
# Narrative: https://appdev.kbase.us/narrative/76990
WORKSPACE_URL=https://kbase.us/services/ws

# Root path for proxy deployment (e.g., "/services/berdl_table_scanner")
# Leave empty if running at root path (i.e., "/") for local dev
ROOT_PATH=/services/berdl_table_scanner
ROOT_PATH=/services/berdl_table_scanner
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
trash/

.DS_Store
.idea
test/test.cfg
Expand All @@ -20,3 +22,9 @@ venv/

# Environment variables
.env

# External libraries (cloned)
lib/

# Cache directory
cache/
58 changes: 52 additions & 6 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,64 @@
"""
Configuration settings for TableScanner application.

Loads configuration from environment variables and .env file.
All KBase service URLs and authentication settings are managed here.
"""

from pydantic_settings import BaseSettings
from pydantic import Field


class Settings(BaseSettings):
"""Application settings."""
"""
Application settings loaded from environment variables.

Create a .env file based on .env.example to configure locally.
"""

# ==========================================================================
# AUTHENTICATION
# ==========================================================================
KB_SERVICE_AUTH_TOKEN: str = Field(
...,
description="KBase authentication token for API access"
)

# ==========================================================================
# CACHE SETTINGS
# ==========================================================================
CACHE_DIR: str = Field(
default="/tmp/tablescanner_cache",
description="Directory for caching downloaded files and SQLite databases"
)
CACHE_MAX_AGE_HOURS: int = Field(
default=24,
description="Maximum age of cached files in hours before re-download"
)

KB_SERVICE_AUTH_TOKEN: str
CACHE_DIR: str
# ==========================================================================
# KBASE SERVICE URLS
# ==========================================================================
WORKSPACE_URL: str = Field(
default="https://kbase.us/services/ws",
description="KBase Workspace service URL"
)
KBASE_ENDPOINT: str = Field(
default="https://kbase.us/services",
description="Base URL for KBase services"
)
BLOBSTORE_URL: str = Field(
default="https://kbase.us/services/shock-api",
description="KBase blobstore/shock service URL"
)

# KBase Workspace settings
WORKSPACE_URL: str
# ==========================================================================
# APPLICATION SETTINGS
# ==========================================================================
DEBUG: bool = Field(
default=False,
description="Enable debug mode with verbose logging"
)

# Root path for proxy deployment (e.g., "/services/berdl_table_scanner")
ROOT_PATH: str = ""
Expand All @@ -23,5 +69,5 @@ class Config:
case_sensitive = True


# Global settings instance
# Global settings instance - loaded at module import
settings = Settings()
48 changes: 44 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
"""
TableScanner FastAPI Application

Main application factory module.
Main application factory module for the TableScanner service.
Provides REST API endpoints for querying BERDL table data.

Run with: uv run fastapi dev app/main.py
"""

from pathlib import Path
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

from app.routes import router
from app.config import settings

Expand All @@ -13,22 +20,55 @@ def create_app() -> FastAPI:
"""
Application factory function.

Creates and configures the FastAPI application with:
- Static file serving for viewer.html
- API routes

Returns:
FastAPI: Configured FastAPI application instance
"""
# Configure root_path for KBase dynamic services
# KBase services are often deployed at /services/service_name
# Pydantic Settings management or manual environ check can handle this.
import os
root_path = os.environ.get("KB_SERVICE_ROOT_PATH", "")


description = """
## TableScanner API

A FastAPI service for querying BERDL table data from KBase.

### Features
- List pangenomes from BERDLTables objects
- List tables within a pangenome
- Query table data with filtering, sorting, and pagination
- Local caching for performance

### Authentication
Pass your KBase auth token in the `Authorization` header.
"""

app = FastAPI(
title="TableScanner",
description="API for table scanning operations",
root_path=root_path,
description=description,
version="1.0.0",
root_path=settings.ROOT_PATH
docs_url="/docs",
redoc_url="/redoc",
)

# Store settings in app state for access throughout the application
app.state.settings = settings

# Include routes
# Include API routes
app.include_router(router)

# Mount static files directory for viewer.html
static_dir = Path(__file__).parent.parent / "static"
if static_dir.exists():
app.mount("/static", StaticFiles(directory=static_dir), name="static")

return app


Expand Down
Loading
Loading