agr-curation-api-client 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ """AGR Curation API Client.
2
+
3
+ A unified Python client for Alliance of Genome Resources (AGR) A-Team curation APIs.
4
+ """
5
+
6
+ from .client import AGRCurationAPIClient
7
+ from .exceptions import (
8
+ AGRAPIError,
9
+ AGRAuthenticationError,
10
+ AGRConnectionError,
11
+ AGRTimeoutError,
12
+ AGRValidationError,
13
+ )
14
+ from .models import (
15
+ APIConfig,
16
+ Gene,
17
+ Species,
18
+ OntologyTerm,
19
+ ExpressionAnnotation,
20
+ Allele,
21
+ APIResponse,
22
+ )
23
+
24
+ __version__ = "0.1.0"
25
+ __all__ = [
26
+ "AGRCurationAPIClient",
27
+ "AGRAPIError",
28
+ "AGRAuthenticationError",
29
+ "AGRConnectionError",
30
+ "AGRTimeoutError",
31
+ "AGRValidationError",
32
+ "APIConfig",
33
+ "Gene",
34
+ "Species",
35
+ "OntologyTerm",
36
+ "ExpressionAnnotation",
37
+ "Allele",
38
+ "APIResponse",
39
+ ]
@@ -0,0 +1,347 @@
1
+ """Main client for AGR Curation API."""
2
+
3
+ import json
4
+ import logging
5
+ import urllib.request
6
+ from typing import Optional, Dict, Any, List, Union, Type
7
+ from types import TracebackType
8
+
9
+ from pydantic import ValidationError
10
+ from fastapi_okta.okta_utils import get_authentication_token, generate_headers
11
+
12
+ from .models import (
13
+ APIConfig,
14
+ Gene,
15
+ Species,
16
+ OntologyTerm,
17
+ ExpressionAnnotation,
18
+ Allele,
19
+ APIResponse,
20
+ )
21
+ from .exceptions import (
22
+ AGRAPIError,
23
+ AGRAuthenticationError,
24
+ AGRValidationError,
25
+ )
26
+
27
+ logger = logging.getLogger(__name__)
28
+
29
+
30
+ class AGRCurationAPIClient:
31
+ """Client for interacting with AGR A-Team Curation API."""
32
+
33
+ def __init__(self, config: Union[APIConfig, Dict[str, Any], None] = None):
34
+ """Initialize the API client.
35
+
36
+ Args:
37
+ config: API configuration object, dictionary, or None for defaults
38
+ """
39
+ if config is None:
40
+ config = APIConfig() # type: ignore[call-arg]
41
+ elif isinstance(config, dict):
42
+ config = APIConfig(**config)
43
+
44
+ self.config = config
45
+ self.base_url = str(self.config.base_url)
46
+
47
+ # Initialize authentication token if not provided
48
+ if not self.config.okta_token:
49
+ self.config.okta_token = get_authentication_token()
50
+
51
+ def _get_headers(self) -> Dict[str, str]:
52
+ """Get headers with authentication token."""
53
+ if self.config.okta_token:
54
+ headers = generate_headers(self.config.okta_token)
55
+ return dict(headers) # Ensure we return Dict[str, str]
56
+ return {"Content-Type": "application/json", "Accept": "application/json"}
57
+
58
+ def __enter__(self) -> "AGRCurationAPIClient":
59
+ """Context manager entry."""
60
+ return self
61
+
62
+ def __exit__(
63
+ self,
64
+ exc_type: Optional[Type[BaseException]],
65
+ exc_val: Optional[BaseException],
66
+ exc_tb: Optional[TracebackType]
67
+ ) -> None:
68
+ """Context manager exit."""
69
+ pass
70
+
71
+ def _make_request(
72
+ self,
73
+ method: str,
74
+ endpoint: str,
75
+ data: Optional[Dict[str, Any]] = None,
76
+ ) -> Dict[str, Any]:
77
+ """Make a request to the A-Team API.
78
+
79
+ Args:
80
+ method: HTTP method (GET, POST, etc.)
81
+ endpoint: API endpoint
82
+ data: Request data for POST requests
83
+
84
+ Returns:
85
+ Response data as dictionary
86
+
87
+ Raises:
88
+ AGRAPIError: On API errors
89
+ AGRAuthenticationError: On authentication failures
90
+ """
91
+ url = f"{self.base_url}/{endpoint.lstrip('/')}"
92
+ headers = self._get_headers()
93
+
94
+ try:
95
+ if method.upper() == "GET":
96
+ request = urllib.request.Request(url=url, headers=headers)
97
+ else:
98
+ request_data = json.dumps(data or {}).encode('utf-8')
99
+ request = urllib.request.Request(
100
+ url=url,
101
+ method=method.upper(),
102
+ headers=headers,
103
+ data=request_data
104
+ )
105
+
106
+ with urllib.request.urlopen(request) as response:
107
+ if response.getcode() == 200:
108
+ logger.debug("Request successful")
109
+ res = response.read().decode('utf-8')
110
+ return dict(json.loads(res)) # Ensure we return Dict[str, Any]
111
+ else:
112
+ raise AGRAPIError(f"Request failed with status: {response.getcode()}")
113
+
114
+ except urllib.error.HTTPError as e:
115
+ if e.code == 401:
116
+ raise AGRAuthenticationError("Authentication failed")
117
+ else:
118
+ raise AGRAPIError(f"HTTP error {e.code}: {e.reason}")
119
+ except Exception as e:
120
+ raise AGRAPIError(f"Request failed: {str(e)}")
121
+
122
+ # Gene endpoints
123
+ def get_genes(
124
+ self,
125
+ data_provider: Optional[str] = None,
126
+ limit: int = 5000,
127
+ page: int = 0
128
+ ) -> List[Gene]:
129
+ """Get genes from A-Team API.
130
+
131
+ Args:
132
+ data_provider: Filter by data provider abbreviation (e.g., 'WB', 'MGI')
133
+ limit: Number of results per page
134
+ page: Page number (0-based)
135
+
136
+ Returns:
137
+ List of Gene objects
138
+ """
139
+ req_data = {}
140
+ if data_provider:
141
+ req_data["dataProvider.abbreviation"] = data_provider
142
+
143
+ url = f"gene/find?limit={limit}&page={page}"
144
+ response_data = self._make_request("POST", url, req_data)
145
+
146
+ genes = []
147
+ if "results" in response_data:
148
+ for gene_data in response_data["results"]:
149
+ try:
150
+ genes.append(Gene(**gene_data))
151
+ except ValidationError as e:
152
+ logger.warning(f"Failed to parse gene data: {e}")
153
+
154
+ return genes
155
+
156
+ def get_gene(self, gene_id: str) -> Optional[Gene]:
157
+ """Get a specific gene by ID.
158
+
159
+ Args:
160
+ gene_id: Gene curie or primary external ID
161
+
162
+ Returns:
163
+ Gene object or None if not found
164
+ """
165
+ try:
166
+ response_data = self._make_request("GET", f"gene/{gene_id}")
167
+ return Gene(**response_data)
168
+ except AGRAPIError:
169
+ return None
170
+
171
+ # Species endpoints
172
+ def get_species(self, limit: int = 100, page: int = 0) -> List[Species]:
173
+ """Get species data from A-Team API.
174
+
175
+ Args:
176
+ limit: Number of results per page
177
+ page: Page number (0-based)
178
+
179
+ Returns:
180
+ List of Species objects
181
+ """
182
+ url = f"species/findForPublic?limit={limit}&page={page}&view=ForPublic"
183
+ response_data = self._make_request("POST", url, {})
184
+
185
+ species_list = []
186
+ if "results" in response_data:
187
+ for species_data in response_data["results"]:
188
+ try:
189
+ species_list.append(Species(**species_data))
190
+ except ValidationError as e:
191
+ logger.warning(f"Failed to parse species data: {e}")
192
+
193
+ return species_list
194
+
195
+ # Ontology endpoints
196
+ def get_ontology_root_nodes(self, node_type: str) -> List[OntologyTerm]:
197
+ """Get ontology root nodes.
198
+
199
+ Args:
200
+ node_type: Type of ontology node (e.g., 'goterm', 'doterm', 'anatomicalterm')
201
+
202
+ Returns:
203
+ List of OntologyTerm objects
204
+ """
205
+ response_data = self._make_request("GET", f"{node_type}/rootNodes")
206
+
207
+ terms = []
208
+ if "entities" in response_data:
209
+ for term_data in response_data["entities"]:
210
+ if not term_data.get("obsolete", False):
211
+ try:
212
+ terms.append(OntologyTerm(**term_data))
213
+ except ValidationError as e:
214
+ logger.warning(f"Failed to parse ontology term: {e}")
215
+
216
+ return terms
217
+
218
+ def get_ontology_node_children(self, node_curie: str, node_type: str) -> List[OntologyTerm]:
219
+ """Get children of an ontology node.
220
+
221
+ Args:
222
+ node_curie: CURIE of the parent node
223
+ node_type: Type of ontology node
224
+
225
+ Returns:
226
+ List of child OntologyTerm objects
227
+ """
228
+ response_data = self._make_request("GET", f"{node_type}/{node_curie}/children")
229
+
230
+ terms = []
231
+ if "entities" in response_data:
232
+ for term_data in response_data["entities"]:
233
+ if not term_data.get("obsolete", False):
234
+ try:
235
+ terms.append(OntologyTerm(**term_data))
236
+ except ValidationError as e:
237
+ logger.warning(f"Failed to parse ontology term: {e}")
238
+
239
+ return terms
240
+
241
+ # Expression annotation endpoints
242
+ def get_expression_annotations(
243
+ self,
244
+ data_provider: str,
245
+ limit: int = 5000,
246
+ page: int = 0
247
+ ) -> List[ExpressionAnnotation]:
248
+ """Get expression annotations from A-Team API.
249
+
250
+ Args:
251
+ data_provider: Data provider abbreviation
252
+ limit: Number of results per page
253
+ page: Page number (0-based)
254
+
255
+ Returns:
256
+ List of ExpressionAnnotation objects
257
+ """
258
+ req_data = {"expressionAnnotationSubject.dataProvider.abbreviation": data_provider}
259
+ url = f"gene-expression-annotation/findForPublic?limit={limit}&page={page}&view=ForPublic"
260
+
261
+ response_data = self._make_request("POST", url, req_data)
262
+
263
+ annotations = []
264
+ if "results" in response_data:
265
+ for annotation_data in response_data["results"]:
266
+ try:
267
+ annotations.append(ExpressionAnnotation(**annotation_data))
268
+ except ValidationError as e:
269
+ logger.warning(f"Failed to parse expression annotation: {e}")
270
+
271
+ return annotations
272
+
273
+ # Allele endpoints
274
+ def get_alleles(
275
+ self,
276
+ data_provider: Optional[str] = None,
277
+ limit: int = 5000,
278
+ page: int = 0
279
+ ) -> List[Allele]:
280
+ """Get alleles from A-Team API.
281
+
282
+ Args:
283
+ data_provider: Filter by data provider abbreviation
284
+ limit: Number of results per page
285
+ page: Page number (0-based)
286
+
287
+ Returns:
288
+ List of Allele objects
289
+ """
290
+ req_data = {}
291
+ if data_provider:
292
+ req_data["dataProvider.abbreviation"] = data_provider
293
+
294
+ url = f"allele/find?limit={limit}&page={page}"
295
+ response_data = self._make_request("POST", url, req_data)
296
+
297
+ alleles = []
298
+ if "results" in response_data:
299
+ for allele_data in response_data["results"]:
300
+ try:
301
+ alleles.append(Allele(**allele_data))
302
+ except ValidationError as e:
303
+ logger.warning(f"Failed to parse allele data: {e}")
304
+
305
+ return alleles
306
+
307
+ def get_allele(self, allele_id: str) -> Optional[Allele]:
308
+ """Get a specific allele by ID.
309
+
310
+ Args:
311
+ allele_id: Allele curie or primary external ID
312
+
313
+ Returns:
314
+ Allele object or None if not found
315
+ """
316
+ try:
317
+ response_data = self._make_request("GET", f"allele/{allele_id}")
318
+ return Allele(**response_data)
319
+ except AGRAPIError:
320
+ return None
321
+
322
+ # Search methods
323
+ def search_entities(
324
+ self,
325
+ entity_type: str,
326
+ search_filters: Dict[str, Any],
327
+ limit: int = 5000,
328
+ page: int = 0
329
+ ) -> APIResponse:
330
+ """Generic search method for any entity type.
331
+
332
+ Args:
333
+ entity_type: Type of entity to search (e.g., 'gene', 'allele', 'species')
334
+ search_filters: Dictionary of search filters
335
+ limit: Number of results per page
336
+ page: Page number (0-based)
337
+
338
+ Returns:
339
+ APIResponse with search results
340
+ """
341
+ url = f"{entity_type}/find?limit={limit}&page={page}"
342
+ response_data = self._make_request("POST", url, search_filters)
343
+
344
+ try:
345
+ return APIResponse(**response_data)
346
+ except ValidationError as e:
347
+ raise AGRValidationError(f"Invalid API response: {str(e)}")
@@ -0,0 +1,43 @@
1
+ """Exception classes for AGR Curation API Client."""
2
+
3
+ from typing import Optional, Dict, Any
4
+
5
+
6
+ class AGRAPIError(Exception):
7
+ """Base exception for all AGR API errors."""
8
+
9
+ def __init__(self, message: str, status_code: Optional[int] = None, response_data: Optional[Dict[str, Any]] = None):
10
+ """Initialize AGR API error.
11
+
12
+ Args:
13
+ message: Error message
14
+ status_code: HTTP status code if applicable
15
+ response_data: Response data from API if available
16
+ """
17
+ super().__init__(message)
18
+ self.status_code = status_code
19
+ self.response_data = response_data
20
+
21
+
22
+ class AGRAuthenticationError(AGRAPIError):
23
+ """Raised when authentication fails."""
24
+
25
+ pass
26
+
27
+
28
+ class AGRConnectionError(AGRAPIError):
29
+ """Raised when connection to API fails."""
30
+
31
+ pass
32
+
33
+
34
+ class AGRTimeoutError(AGRAPIError):
35
+ """Raised when API request times out."""
36
+
37
+ pass
38
+
39
+
40
+ class AGRValidationError(AGRAPIError):
41
+ """Raised when request validation fails."""
42
+
43
+ pass
@@ -0,0 +1,132 @@
1
+ """Data models for AGR Curation API Client."""
2
+
3
+ from typing import Optional, Dict, Any
4
+ from pydantic import BaseModel, Field, HttpUrl, field_validator
5
+ from datetime import timedelta
6
+
7
+
8
+ class APIConfig(BaseModel):
9
+ """Configuration for AGR Curation API client."""
10
+
11
+ base_url: HttpUrl = Field(
12
+ default_factory=lambda: HttpUrl("https://curation.alliancegenome.org/api"),
13
+ description="Base URL for the A-Team Curation API"
14
+ )
15
+ okta_token: Optional[str] = Field(None, description="Okta bearer token for authentication")
16
+ timeout: timedelta = Field(
17
+ default=timedelta(seconds=30),
18
+ description="Request timeout"
19
+ )
20
+ max_retries: int = Field(3, ge=0, description="Maximum number of retry attempts")
21
+ retry_delay: timedelta = Field(
22
+ default=timedelta(seconds=1),
23
+ description="Delay between retry attempts"
24
+ )
25
+ verify_ssl: bool = Field(True, description="Whether to verify SSL certificates")
26
+ headers: Dict[str, str] = Field(
27
+ default_factory=dict,
28
+ description="Additional headers to include in requests"
29
+ )
30
+
31
+ @field_validator('timeout', 'retry_delay')
32
+ def validate_timedelta(cls, v: timedelta) -> timedelta:
33
+ """Ensure timedelta is positive."""
34
+ if v.total_seconds() <= 0:
35
+ raise ValueError("Timeout and retry_delay must be positive")
36
+ return v
37
+
38
+ class Config:
39
+ """Pydantic config."""
40
+
41
+ json_encoders = {
42
+ timedelta: lambda v: v.total_seconds()
43
+ }
44
+
45
+
46
+ class Gene(BaseModel):
47
+ """Gene model from A-Team curation API."""
48
+
49
+ curie: Optional[str] = Field(None, description="Compact URI")
50
+ primary_external_id: Optional[str] = Field(None, alias="primaryExternalId", description="Primary external ID")
51
+ gene_symbol: Optional[dict] = Field(None, alias="geneSymbol", description="Gene symbol object")
52
+ gene_full_name: Optional[dict] = Field(None, alias="geneFullName", description="Gene full name object")
53
+ gene_systematic_name: Optional[dict] = Field(None, alias="geneSystematicName", description="Gene systematic name")
54
+ gene_synonyms: Optional[list[dict]] = Field(None, alias="geneSynonyms", description="Gene synonyms")
55
+ data_provider: Optional[dict] = Field(None, alias="dataProvider", description="Data provider")
56
+ taxon: Optional[dict] = Field(None, description="Taxon information")
57
+ obsolete: bool = Field(False, description="Whether gene is obsolete")
58
+
59
+ class Config:
60
+ populate_by_name = True
61
+
62
+
63
+ class Species(BaseModel):
64
+ """Species model from A-Team curation API."""
65
+
66
+ curie: Optional[str] = Field(None, description="Compact URI")
67
+ abbreviation: str = Field(..., description="Species abbreviation")
68
+ display_name: Optional[str] = Field(None, alias="displayName", description="Display name")
69
+ full_name: Optional[str] = Field(None, alias="fullName", description="Full scientific name")
70
+
71
+ class Config:
72
+ populate_by_name = True
73
+
74
+
75
+ class OntologyTerm(BaseModel):
76
+ """Ontology term model from A-Team curation API."""
77
+
78
+ curie: str = Field(..., description="Compact URI")
79
+ name: Optional[str] = Field(None, description="Term name")
80
+ definition: Optional[str] = Field(None, description="Term definition")
81
+ synonyms: Optional[list[dict]] = Field(None, description="Term synonyms")
82
+ obsolete: bool = Field(False, description="Whether term is obsolete")
83
+ namespace: Optional[str] = Field(None, description="Ontology namespace")
84
+
85
+ class Config:
86
+ populate_by_name = True
87
+
88
+
89
+ class ExpressionAnnotation(BaseModel):
90
+ """Expression annotation model from A-Team curation API."""
91
+
92
+ curie: Optional[str] = Field(None, description="Compact URI")
93
+ expression_annotation_subject: Optional[dict] = Field(
94
+ None,
95
+ alias="expressionAnnotationSubject",
96
+ description="Expression annotation subject"
97
+ )
98
+ expression_pattern: Optional[dict] = Field(
99
+ None,
100
+ alias="expressionPattern",
101
+ description="Expression pattern"
102
+ )
103
+
104
+ class Config:
105
+ populate_by_name = True
106
+
107
+
108
+ class Allele(BaseModel):
109
+ """Allele model from A-Team curation API."""
110
+
111
+ curie: Optional[str] = Field(None, description="Compact URI")
112
+ primary_external_id: Optional[str] = Field(None, alias="primaryExternalId", description="Primary external ID")
113
+ allele_symbol: Optional[dict] = Field(None, alias="alleleSymbol", description="Allele symbol")
114
+ allele_full_name: Optional[dict] = Field(None, alias="alleleFullName", description="Allele full name")
115
+ allele_synonyms: Optional[list[dict]] = Field(None, alias="alleleSynonyms", description="Allele synonyms")
116
+ data_provider: Optional[dict] = Field(None, alias="dataProvider", description="Data provider")
117
+ taxon: Optional[dict] = Field(None, description="Taxon information")
118
+ obsolete: bool = Field(False, description="Whether allele is obsolete")
119
+
120
+ class Config:
121
+ populate_by_name = True
122
+
123
+
124
+ class APIResponse(BaseModel):
125
+ """Standard A-Team API response wrapper."""
126
+
127
+ total_results: int = Field(..., alias="totalResults", description="Total number of results")
128
+ returned_records: int = Field(..., alias="returnedRecords", description="Number of records returned")
129
+ results: list[Any] = Field(..., description="Result data")
130
+
131
+ class Config:
132
+ populate_by_name = True
File without changes
@@ -0,0 +1,321 @@
1
+ Metadata-Version: 2.4
2
+ Name: agr-curation-api-client
3
+ Version: 0.1.0
4
+ Summary: Unified Python client for Alliance of Genome Resources (AGR) curation APIs
5
+ Author-email: Alliance of Genome Resources <valearna@caltech.edu>
6
+ Maintainer-email: Alliance Blue Team <valearna@caltech.edu>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/alliance-genome/agr_curation_api_client
9
+ Project-URL: Bug Reports, https://github.com/alliance-genome/agr_curation_api_client/issues
10
+ Project-URL: Source, https://github.com/alliance-genome/agr_curation_api_client
11
+ Project-URL: Documentation, https://github.com/alliance-genome/agr_curation_api_client#readme
12
+ Keywords: agr,alliance,genome,curation,api,client
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.28.0
27
+ Requires-Dist: pydantic>=2.0.0
28
+ Requires-Dist: httpx>=0.24.0
29
+ Requires-Dist: tenacity>=8.0.0
30
+ Requires-Dist: python-dateutil>=2.8.0
31
+ Requires-Dist: fastapi_okta>=1.3.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
34
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
35
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
38
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
39
+ Requires-Dist: types-requests; extra == "dev"
40
+ Requires-Dist: types-python-dateutil; extra == "dev"
41
+ Dynamic: license-file
42
+
43
+ # AGR Curation API Client
44
+
45
+ A unified Python client for Alliance of Genome Resources (AGR) curation APIs.
46
+
47
+ ## Features
48
+
49
+ - **Unified Interface**: Single client for all AGR curation API endpoints
50
+ - **Type Safety**: Full type hints and Pydantic models for request/response validation
51
+ - **Retry Logic**: Automatic retry with exponential backoff for transient failures
52
+ - **Authentication**: Support for API key and Okta token authentication
53
+ - **Async Support**: Built on httpx for both sync and async operations
54
+ - **Comprehensive Error Handling**: Detailed exceptions for different error scenarios
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ pip install agr-curation-api-client
60
+ ```
61
+
62
+ For development:
63
+ ```bash
64
+ git clone https://github.com/alliance-genome/agr_curation_api_client.git
65
+ cd agr_curation_api_client
66
+ make install-dev
67
+ ```
68
+
69
+ ## Authentication
70
+
71
+ The client supports automatic Okta token generation using the same environment variables as other AGR services:
72
+
73
+ ```bash
74
+ export OKTA_DOMAIN="your-okta-domain"
75
+ export OKTA_API_AUDIENCE="your-api-audience"
76
+ export OKTA_CLIENT_ID="your-client-id"
77
+ export OKTA_CLIENT_SECRET="your-client-secret"
78
+ ```
79
+
80
+ With these environment variables set, the client will automatically obtain an authentication token when initialized.
81
+
82
+ ## Quick Start
83
+
84
+ ### Basic Usage
85
+
86
+ ```python
87
+ from agr_curation_api import AGRCurationAPIClient, APIConfig
88
+
89
+ # Option 1: Automatic authentication (requires OKTA env vars)
90
+ client = AGRCurationAPIClient()
91
+
92
+ # Option 2: Manual token configuration
93
+ config = APIConfig(
94
+ base_url="https://curation.alliancegenome.org/api",
95
+ okta_token="your-okta-token" # Optional - will auto-retrieve if not provided
96
+ )
97
+ client = AGRCurationAPIClient(config)
98
+
99
+ # Use the client
100
+ with client:
101
+ # Get genes from WormBase
102
+ genes = client.get_genes(data_provider="WB", limit=10)
103
+
104
+ for gene in genes:
105
+ symbol = gene.gene_symbol.get("displayText", "") if gene.gene_symbol else ""
106
+ print(f"{gene.curie}: {symbol}")
107
+ ```
108
+
109
+ ### Working with Genes
110
+
111
+ ```python
112
+ from agr_curation_api import AGRCurationAPIClient, Gene
113
+
114
+ # Use default configuration
115
+ client = AGRCurationAPIClient()
116
+
117
+ # Get genes from a specific data provider
118
+ wb_genes = client.get_genes(data_provider="WB", limit=100)
119
+ print(f"Found {len(wb_genes)} WormBase genes")
120
+
121
+ # Get a specific gene by ID
122
+ gene = client.get_gene("WB:WBGene00001234")
123
+ if gene:
124
+ print(f"Gene: {gene.gene_symbol}")
125
+ print(f"Full name: {gene.gene_full_name}")
126
+ print(f"Species: {gene.taxon}")
127
+
128
+ # Get all genes (paginated)
129
+ all_genes = client.get_genes(limit=5000, page=0)
130
+ ```
131
+
132
+ ### Working with Species
133
+
134
+ ```python
135
+ # Get all species
136
+ species_list = client.get_species()
137
+
138
+ for species in species_list:
139
+ print(f"{species.abbreviation}: {species.display_name}")
140
+
141
+ # Find a specific species
142
+ wb_species = [s for s in species_list if s.abbreviation == "WB"]
143
+ if wb_species:
144
+ print(f"WormBase: {wb_species[0].full_name}")
145
+ ```
146
+
147
+ ### Working with Ontology Terms
148
+
149
+ ```python
150
+ # Get GO term root nodes
151
+ go_roots = client.get_ontology_root_nodes("goterm")
152
+ print(f"Found {len(go_roots)} GO root terms")
153
+
154
+ # Get children of a specific GO term
155
+ children = client.get_ontology_node_children("GO:0008150", "goterm") # biological_process
156
+ for child in children:
157
+ print(f"{child.curie}: {child.name}")
158
+
159
+ # Get disease ontology terms
160
+ disease_roots = client.get_ontology_root_nodes("doterm")
161
+
162
+ # Get anatomical terms
163
+ anatomy_roots = client.get_ontology_root_nodes("anatomicalterm")
164
+ ```
165
+
166
+ ### Working with Expression Annotations
167
+
168
+ ```python
169
+ # Get expression annotations for WormBase
170
+ wb_expressions = client.get_expression_annotations(
171
+ data_provider="WB",
172
+ limit=100
173
+ )
174
+
175
+ for expr in wb_expressions:
176
+ if expr.expression_annotation_subject:
177
+ gene_id = expr.expression_annotation_subject.get("primaryExternalId")
178
+ gene_symbol = expr.expression_annotation_subject.get("geneSymbol", {}).get("displayText")
179
+ print(f"Gene: {gene_id} ({gene_symbol})")
180
+
181
+ if expr.expression_pattern:
182
+ anatomy = expr.expression_pattern.get("whereExpressed", {}).get("anatomicalStructure", {}).get("curie")
183
+ print(f" Expressed in: {anatomy}")
184
+ ```
185
+
186
+ ### Working with Alleles
187
+
188
+ ```python
189
+ # Get alleles from a specific data provider
190
+ wb_alleles = client.get_alleles(data_provider="WB", limit=50)
191
+
192
+ for allele in wb_alleles:
193
+ symbol = allele.allele_symbol.get("displayText", "") if allele.allele_symbol else ""
194
+ print(f"{allele.curie}: {symbol}")
195
+
196
+ # Get a specific allele
197
+ allele = client.get_allele("WB:WBVar00001234")
198
+ if allele:
199
+ print(f"Allele: {allele.allele_symbol}")
200
+ print(f"Full name: {allele.allele_full_name}")
201
+ ```
202
+
203
+ ### Generic Search
204
+
205
+ ```python
206
+ # Generic entity search
207
+ search_filters = {
208
+ "dataProvider.abbreviation": "WB",
209
+ "geneSymbol.displayText": "daf-16"
210
+ }
211
+
212
+ results = client.search_entities(
213
+ entity_type="gene",
214
+ search_filters=search_filters,
215
+ limit=10
216
+ )
217
+
218
+ print(f"Total results: {results.total_results}")
219
+ print(f"Returned: {results.returned_records}")
220
+
221
+ for gene_data in results.results:
222
+ print(f"Found gene: {gene_data}")
223
+ ```
224
+
225
+ ### Error Handling
226
+
227
+ ```python
228
+ from agr_curation_api import (
229
+ AGRAPIError,
230
+ AGRAuthenticationError,
231
+ AGRConnectionError,
232
+ AGRTimeoutError,
233
+ AGRValidationError
234
+ )
235
+
236
+ try:
237
+ reference = client.get_reference("invalid-id")
238
+ except AGRAuthenticationError:
239
+ print("Authentication failed - check your credentials")
240
+ except AGRValidationError as e:
241
+ print(f"Invalid data: {e}")
242
+ except AGRTimeoutError:
243
+ print("Request timed out - try again later")
244
+ except AGRConnectionError:
245
+ print("Connection failed - check network")
246
+ except AGRAPIError as e:
247
+ print(f"API error: {e}")
248
+ if e.status_code:
249
+ print(f"Status code: {e.status_code}")
250
+ ```
251
+
252
+ ## Configuration Options
253
+
254
+ The `APIConfig` class supports the following options:
255
+
256
+ - `base_url`: Base URL for the A-Team Curation API (default: "https://curation.alliancegenome.org/api")
257
+ - `okta_token`: Okta bearer token for authentication (auto-retrieved if not provided)
258
+ - `timeout`: Request timeout in seconds (default: 30)
259
+ - `max_retries`: Maximum retry attempts (default: 3)
260
+ - `retry_delay`: Initial delay between retries in seconds (default: 1)
261
+ - `verify_ssl`: Whether to verify SSL certificates (default: True)
262
+ - `headers`: Additional headers to include in requests
263
+
264
+ ### Environment Variables
265
+
266
+ The client uses the following environment variables for configuration:
267
+
268
+ - `ATEAM_API`: Override the default A-Team API URL (default: uses production curation API)
269
+ - `OKTA_DOMAIN`: Your Okta domain (required for automatic authentication)
270
+ - `OKTA_API_AUDIENCE`: Your API audience (required for automatic authentication)
271
+ - `OKTA_CLIENT_ID`: Your Okta client ID (required for automatic authentication)
272
+ - `OKTA_CLIENT_SECRET`: Your Okta client secret (required for automatic authentication)
273
+
274
+ ## Development
275
+
276
+ ### Running Tests
277
+
278
+ ```bash
279
+ make test
280
+ ```
281
+
282
+ ### Code Quality
283
+
284
+ ```bash
285
+ # Run linting
286
+ make lint
287
+
288
+ # Run type checking
289
+ make type-check
290
+
291
+ # Format code
292
+ make format
293
+
294
+ # Run all checks
295
+ make check
296
+ ```
297
+
298
+ ### Building Documentation
299
+
300
+ ```bash
301
+ cd docs
302
+ make html
303
+ ```
304
+
305
+ ## Contributing
306
+
307
+ 1. Fork the repository
308
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
309
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
310
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
311
+ 5. Open a Pull Request
312
+
313
+ ## License
314
+
315
+ This project is licensed under the MIT License - see the LICENSE file for details.
316
+
317
+ ## Support
318
+
319
+ - **Issues**: [GitHub Issues](https://github.com/alliance-genome/agr_curation_api_client/issues)
320
+ - **Documentation**: [API Documentation](https://alliancegenome.org/api-docs)
321
+ - **Contact**: software@alliancegenome.org
@@ -0,0 +1,10 @@
1
+ agr_curation_api/__init__.py,sha256=CuU6FLasKqfC44NSMJJMtXdw7WirOJQMZrnGOQKCiio,751
2
+ agr_curation_api/client.py,sha256=q3zxvLT883ze81l0eTPDzf1oS0FU1RJHXh6ikJBVs0M,11123
3
+ agr_curation_api/exceptions.py,sha256=uL8n1HedcKb6-expueINIqGOT94LudtUBWG0VlldMAM,1019
4
+ agr_curation_api/models.py,sha256=385HApbQNnICxOSxdXOxQfYG9sHpuE6EnuRKp4pPnvc,5331
5
+ agr_curation_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ agr_curation_api_client-0.1.0.dist-info/licenses/LICENSE,sha256=8TExF0H0g2oKEU4iBjTwrHl2_-1SeyI0RbXlP9wpk3c,1084
7
+ agr_curation_api_client-0.1.0.dist-info/METADATA,sha256=FLpdtk5_1LIciDwBY1MZOzqjJ_mA8pYrVy3IFGOX_vc,9533
8
+ agr_curation_api_client-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ agr_curation_api_client-0.1.0.dist-info/top_level.txt,sha256=tgbwvkzQIp6Tc8co8KZrlAWJ3nJIGcg3R9rlQz4ooPQ,17
10
+ agr_curation_api_client-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alliance of Genome Resources
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ agr_curation_api