Skip to content

Commit c367c4f

Browse files
committed
Add docstring docs
1 parent 1ced45b commit c367c4f

14 files changed

Lines changed: 1646 additions & 224 deletions

File tree

dapi/__init__.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
1-
"""
2-
Dapi - A Python wrapper for interacting with DesignSafe resources via the Tapis API.
1+
"""Dapi - A Python wrapper for interacting with DesignSafe resources via the Tapis API.
2+
3+
This package provides a high-level, user-friendly interface for working with DesignSafe
4+
resources through the Tapis V3 API. It simplifies complex operations and provides
5+
organized access to different service areas including authentication, file operations,
6+
job submission and monitoring, application discovery, system information, and database access.
7+
8+
Key Features:
9+
- Simplified authentication with credential resolution hierarchy
10+
- DesignSafe path translation (MyData, projects, etc.) to Tapis URIs
11+
- High-level job submission with automatic app parameter mapping
12+
- Job monitoring with progress bars and status interpretation
13+
- File upload/download with automatic directory creation
14+
- Application discovery and detailed retrieval
15+
- System queue information and resource limits
16+
- Database access for DesignSafe research databases
17+
- Comprehensive error handling with descriptive exceptions
18+
19+
Main Components:
20+
DSClient: Main client class providing organized access to all services
21+
SubmittedJob: Class for managing and monitoring submitted Tapis jobs
22+
Exception classes: Specific exceptions for different error types
23+
24+
Example:
25+
Basic usage with automatic authentication:
26+
27+
>>> from dapi import DSClient
28+
>>> client = DSClient()
29+
Enter DesignSafe Username: myuser
30+
Enter DesignSafe Password: [hidden]
31+
Authentication successful.
32+
33+
>>> # File operations
34+
>>> client.files.upload("/local/file.txt", "/MyData/uploads/file.txt")
35+
>>> files = client.files.list("/MyData/uploads/")
36+
37+
>>> # Job submission and monitoring
38+
>>> job_request = client.jobs.generate_request(
39+
... app_id="matlab-r2023a",
40+
... input_dir_uri="/MyData/analysis/input/",
41+
... script_filename="run_analysis.m"
42+
... )
43+
>>> job = client.jobs.submit_request(job_request)
44+
>>> final_status = job.monitor()
45+
46+
>>> # Database access
47+
>>> df = client.db.ngl.read_sql("SELECT * FROM earthquake_data LIMIT 10")
48+
49+
Attributes:
50+
__version__ (str): The version number of the dapi package.
51+
DSClient: Main client class for DesignSafe API interactions.
52+
SubmittedJob: Class for managing submitted Tapis jobs.
53+
Exception classes: Custom exceptions for specific error conditions.
354
"""
455
from .client import DSClient
556

dapi/apps.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,35 @@
77
def find_apps(
88
t: Tapis, search_term: str, list_type: str = "ALL", verbose: bool = True
99
) -> List[Tapis]:
10-
"""
11-
Search for Tapis apps matching a search term.
10+
"""Search for Tapis apps matching a search term.
11+
12+
Searches through available Tapis applications using partial name matching.
13+
This function helps discover applications available for job submission.
1214
1315
Args:
14-
t: Authenticated Tapis client instance.
15-
search_term: Name or partial name to search for. Use "" for all.
16-
list_type: One of 'OWNED', 'SHARED_PUBLIC', 'SHARED_DIRECT', 'READ_PERM', 'MINE', 'ALL'.
17-
verbose: If True, prints summary of found apps.
16+
t (Tapis): Authenticated Tapis client instance.
17+
search_term (str): Name or partial name to search for. Use empty string
18+
for all apps. Supports partial matching with wildcards.
19+
list_type (str, optional): Type of apps to list. Must be one of:
20+
'OWNED', 'SHARED_PUBLIC', 'SHARED_DIRECT', 'READ_PERM', 'MINE', 'ALL'.
21+
Defaults to "ALL".
22+
verbose (bool, optional): If True, prints summary of found apps including
23+
ID, version, and owner information. Defaults to True.
1824
1925
Returns:
20-
List of matching Tapis app objects.
26+
List[Tapis]: List of matching Tapis app objects with selected fields
27+
(id, version, owner).
2128
2229
Raises:
23-
AppDiscoveryError: If the search fails.
30+
AppDiscoveryError: If the Tapis API search fails or an unexpected
31+
error occurs during the search operation.
32+
33+
Example:
34+
>>> find_apps(client, "matlab", verbose=True)
35+
Found 3 matching apps:
36+
- matlab-r2023a (Version: 1.0, Owner: designsafe)
37+
- matlab-parallel (Version: 2.1, Owner: tacc)
38+
- matlab-desktop (Version: 1.5, Owner: designsafe)
2439
"""
2540
try:
2641
# Use id.like for partial matching, ensure search term is handled
@@ -53,20 +68,35 @@ def find_apps(
5368
def get_app_details(
5469
t: Tapis, app_id: str, app_version: Optional[str] = None, verbose: bool = True
5570
) -> Optional[Tapis]:
56-
"""
57-
Get detailed information for a specific app ID and version (or latest).
71+
"""Get detailed information for a specific app ID and version.
72+
73+
Retrieves comprehensive details about a specific Tapis application,
74+
including job attributes, execution system, and parameter definitions.
5875
5976
Args:
60-
t: Authenticated Tapis client instance.
61-
app_id: Exact app ID to look up.
62-
app_version: Specific app version. If None, fetches the latest version.
63-
verbose: If True, prints basic app info.
77+
t (Tapis): Authenticated Tapis client instance.
78+
app_id (str): Exact app ID to look up. Must match exactly.
79+
app_version (Optional[str], optional): Specific app version to retrieve.
80+
If None, fetches the latest available version. Defaults to None.
81+
verbose (bool, optional): If True, prints basic app information including
82+
ID, version, owner, execution system, and description. Defaults to True.
6483
6584
Returns:
66-
Tapis app object with full details, or None if not found.
85+
Optional[Tapis]: Tapis app object with full details including jobAttributes,
86+
parameterSet, and other configuration. Returns None if the app is not found.
6787
6888
Raises:
69-
AppDiscoveryError: If fetching the app details fails.
89+
AppDiscoveryError: If the Tapis API call fails (except for 404 not found)
90+
or an unexpected error occurs during retrieval.
91+
92+
Example:
93+
>>> app = get_app_details(client, "matlab-r2023a", "1.0")
94+
App Details:
95+
ID: matlab-r2023a
96+
Version: 1.0
97+
Owner: designsafe
98+
Execution System: frontera
99+
Description: MATLAB R2023a runtime environment
70100
"""
71101
try:
72102
if app_version:

dapi/auth.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,54 @@ def init(
1212
password: str = None,
1313
env_file: str = None,
1414
) -> Tapis:
15-
"""
16-
Initialize and authenticate a Tapis client for DesignSafe.
15+
"""Initialize and authenticate a Tapis client for DesignSafe.
16+
17+
Creates and authenticates a Tapis client instance for interacting with
18+
DesignSafe resources. The function follows a credential resolution hierarchy
19+
and handles secure password input when needed.
1720
18-
Tries credentials in this order:
19-
1. Explicitly passed username/password arguments.
20-
2. Environment variables (DESIGNSAFE_USERNAME, DESIGNSAFE_PASSWORD).
21-
Loads from `env_file` (e.g., '.env') if specified, otherwise checks system env.
22-
3. Prompts user for username/password if none found.
21+
Credential Resolution Order:
22+
1. Explicitly passed username/password arguments
23+
2. Environment variables (DESIGNSAFE_USERNAME, DESIGNSAFE_PASSWORD)
24+
- Loads from env_file if specified, otherwise checks system environment
25+
3. Interactive prompts for missing credentials
2326
2427
Args:
25-
base_url: The Tapis base URL for DesignSafe.
26-
username: Explicit DesignSafe username.
27-
password: Explicit DesignSafe password.
28-
env_file: Path to a .env file to load credentials from.
28+
base_url (str, optional): The Tapis base URL for DesignSafe API endpoints.
29+
Defaults to "https://designsafe.tapis.io".
30+
username (str, optional): Explicit DesignSafe username. If None, will
31+
attempt to load from environment or prompt user. Defaults to None.
32+
password (str, optional): Explicit DesignSafe password. If None, will
33+
attempt to load from environment or prompt user securely. Defaults to None.
34+
env_file (str, optional): Path to a .env file containing credentials.
35+
If None, attempts to load from default .env file if it exists.
36+
Defaults to None.
2937
3038
Returns:
31-
An authenticated tapipy.Tapis object.
39+
Tapis: An authenticated tapipy.Tapis client object ready for API calls.
3240
3341
Raises:
34-
AuthenticationError: If authentication fails.
42+
AuthenticationError: If authentication fails due to invalid credentials,
43+
network issues, or if required credentials cannot be obtained.
44+
45+
Example:
46+
>>> # Using explicit credentials
47+
>>> client = init(username="myuser", password="mypass")
48+
Authentication successful.
49+
50+
>>> # Using environment variables or .env file
51+
>>> client = init(env_file=".env")
52+
Authentication successful.
53+
54+
>>> # Interactive authentication
55+
>>> client = init()
56+
Enter DesignSafe Username: myuser
57+
Enter DesignSafe Password: [hidden]
58+
Authentication successful.
59+
60+
Note:
61+
The function disables automatic spec downloads for faster initialization.
62+
Password input uses getpass for secure entry in terminal environments.
3563
"""
3664
# Load environment variables if a file path is provided
3765
if env_file:

0 commit comments

Comments
 (0)