This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the DNAstack client library and CLI, a Python package that provides both a command-line interface and client library for DNAstack services and GA4GH-compatible services. The package is distributed as dnastack-client-library and provides two entry points: dnastack and omics.
- Each commit must begin with the Clickup task ID surrounded by square brackets. Example: [CU-86b53h2wv].
- Branch names must includes the Clickup task ID. E.g. upgrade_Datadog_Java_agent_version_to_v1490-CU-86b53h2wv
- IMPORTANT: Run
eval "$(pyenv init -)" && pyenv activate dnastack-clientbefore any Python, make, uv, or git commit commands. This activates the correct pyenv virtualenv that hasuvand other tools available. make setup- Set up development environment with uv (creates .venv and installs dependencies)
- Use
uv run dnastackto run the CLI (no virtual environment activation needed) - Optionally activate the virtual environment with
source .venv/bin/activateto usednastackdirectly - Examples:
uv run dnastack --help- Show helpuv run dnastack use http://localhost:8093/service-registry- Connect to local publisheruv run dnastack cs list- List all collectionsuv run omics --help- Run the omics CLI variant
make test-unit- Run unit testsmake test-unit-cov- Run unit tests with coverage reportmake test-unit-watch- Run unit tests in watch mode (auto-rerun on file changes)make test-e2e- Run E2E tests using.envfile for configurationmake test-all- Run both unit and E2E testsmake docker-test-all- Run tests across multiple Python versions in Dockermake docker-test-all-baseline- Test with Python 3.11 (minimum supported version)make docker-test-all-stable- Test with Python 3.11 (current stable)make docker-test-all-latest- Test with Python 3.12 (latest)./scripts/run-e2e-tests.sh- Direct E2E test execution script
make lint- Run ruff linter to check code style and errors (zero-tolerance policy - all violations must be fixed)make lint-fix- Auto-fix linting issues and format code with ruff- Runs
uv run ruff check --fix .to auto-fix violations where possible
- Runs
- Configuration: Minimal setup in
pyproject.tomlwith Python 3.11 target and 120 character line length - CI Integration: GitHub Actions workflow (
.github/workflows/lint.yml) uses uv for consistent environment - Version: Fixed at ruff==0.12.0 in pyproject.toml for consistency across environments
- Development Notes:
- Avoid star imports (
from module import *) - use explicit imports for better code clarity - When fixing linting violations in critical modules, add unit tests first to prevent regressions
- Use
make test-unit-covto verify test coverage before making risky changes - Test locally with
actbefore pushing GitHub Actions changes
- Avoid star imports (
IMPORTANT: Always run these checks before committing:
make lint # Check for linting issues
make test-unit # Run unit testsOr use the combined command:
make lint && make test-unitmake package-test- Build and test package installation in clean containermake publish- Build package for distribution (shows publishing instructions)uv build- Build source distribution and wheeluv publish- Publish to PyPI (requires credentials)
make reset- Clean configuration and session filesmake run-notebooks- Start Jupyter notebook server for samplesmake run-notebooks-dev- Start Jupyter with development volume mounts
- Minimum Python version: 3.11
- Development tested on: 3.11, 3.12
- Main dependencies: click, pydantic v1, requests, pyyaml
The CLI uses a modular command structure built on Click with custom formatting:
dnastack/__main__.py- Main CLI entry point with command group registrationdnastack/cli/core/- Core CLI framework with custom formatting and command specsdnastack/cli/commands/- Individual command modules (auth, collections, dataconnect, workbench, etc.)- Commands use
@formatted_commanddecorator withArgumentSpecfor consistent parameter handling
The project follows a service-oriented client pattern:
dnastack/client/- Core client implementationsdnastack/client/factory.py- Dynamic client creation based on service endpointsdnastack/client/base_client.py- Base class for all service clients- Service-specific clients: collections, data_connect, drs, workbench modules
dnastack/client/service_registry/- Service discovery and registration
dnastack/configuration/- Configuration management with context supportdnastack/context/- Context switching for different environments- Configuration supports multiple authentication methods including OAuth2
- Session management in
dnastack/http/session.py
The CLI implements a sophisticated OAuth2 authentication system:
dnastack/http/authenticators/- Core authenticator implementationsdnastack/http/authenticators/oauth2.py- Main OAuth2 authenticator with state managementdnastack/http/authenticators/oauth2_adapter/- OAuth2 flow adapters:device_code_flow.py- Interactive browser-based authentication (e.g., Publisher, Workbench)client_credential.py- Service account authentication (programmatic access)abstract.py- Base adapter class with authentication eventsfactory.py- Adapter selection based on OAuth2 configuration
- Commands trigger authentication when making API requests via
HttpSession OAuth2Authenticatorchecks for valid session, triggers auth if needed- Device code flow: Shows URL for browser authentication, polls for completion
- Tokens stored locally with refresh capability
- Authentication states:
ready,uninitialized,refresh_required,reauth_required
- Publisher: Uses device code flow with custom login handler
- Workbench: Supports both device code and client credentials
- Sessions persist across CLI invocations
- Automatic token refresh using refresh tokens
When accessing protected resources (collections, data, etc.):
- Automatic Authentication: CLI automatically prompts for authentication when accessing protected resources
- No User Rejection: Instead of rejecting requests from unauthenticated users, the CLI initiates the OAuth2 flow
- Seamless Continuation: After successful authentication, the original command continues without user re-execution
- Access Policies: Resources can have different access levels:
- Public: Open access, available to non-authenticated users
- Registered: Requires authentication, triggers login flow automatically
- Custom: Organization-specific access controls
- No-Auth Mode: Use
--no-authflag to skip authentication (useful for public resources) - Error Handling: 401/403 responses trigger authentication unless in no-auth mode
- Service Discovery: Uses service registry pattern for dynamic endpoint discovery
- Authentication: Pluggable authenticator system with multiple OAuth2 flows
- Client Factory: Dynamic client instantiation based on service types
- Context Management: Environment-specific configuration switching
- Alpha Features: Experimental features isolated in
dnastack/alpha/ - Adapter Pattern: OAuth2 flows implemented as pluggable adapters
- Event-Driven Auth: Authentication events for UI feedback
dnastack/cli/- Command-line interfacednastack/client/- Service client implementationsdnastack/alpha/- Experimental alpha featuresdnastack/common/- Shared utilities (logging, events, auth)dnastack/configuration/- Configuration managementdnastack/context/- Context/environment managementdnastack/http/- HTTP session and authentication
tests/cli/- CLI command teststests/client/- Client library teststests/alpha/- Alpha feature tests- E2E tests require environment configuration via
.envfile - Test helpers in
tests/exam_helper*.pyfor different service types