impc-api 2.0.0__tar.gz → 2.1.0__tar.gz
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.
- {impc_api-2.0.0 → impc_api-2.1.0}/PKG-INFO +16 -4
- {impc_api-2.0.0 → impc_api-2.1.0}/README.md +14 -2
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/batch_solr_request.py +20 -8
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/solr_request.py +16 -5
- {impc_api-2.0.0 → impc_api-2.1.0}/pyproject.toml +2 -2
- {impc_api-2.0.0 → impc_api-2.1.0}/LICENSE +0 -0
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/__init__.py +0 -0
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/get_core_fields.py +0 -0
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/utils/__init__.py +0 -0
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/utils/core_fields.json +0 -0
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/utils/validators.py +0 -0
- {impc_api-2.0.0 → impc_api-2.1.0}/impc_api/utils/warnings.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: impc_api
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: A package to facilitate making API requests to the IMPC Solr API
|
|
5
5
|
Author: MPI2, Marina Kan, Diego Pava
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -11,7 +11,7 @@ Requires-Dist: pandas>=2.2.0
|
|
|
11
11
|
Requires-Dist: requests>=2.33.0
|
|
12
12
|
Requires-Dist: tqdm>=4.66.4
|
|
13
13
|
Requires-Dist: pydantic>=2.9
|
|
14
|
-
Requires-Python: >=3.
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
15
|
Project-URL: Homepage, https://github.com/mpi2/impc-api
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
|
|
@@ -21,7 +21,8 @@ Description-Content-Type: text/markdown
|
|
|
21
21
|
|
|
22
22
|
## Installation Instructions
|
|
23
23
|
|
|
24
|
-
0. Ensure that Python is installed on your system. The minimum required version is 3.
|
|
24
|
+
0. Ensure that Python is installed on your system. The minimum required version is 3.12.
|
|
25
|
+
Python 3.10 will not be supported after version 2.0.0.
|
|
25
26
|
|
|
26
27
|
1. **Create a virtual environment (optional but recommended)**:
|
|
27
28
|
On Mac or Linux:
|
|
@@ -76,6 +77,17 @@ num_found, df = solr_request(
|
|
|
76
77
|
)
|
|
77
78
|
```
|
|
78
79
|
|
|
80
|
+
To use another compatible Solr deployment, override the base URL. The same
|
|
81
|
+
argument is available on `batch_solr_request`:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
num_found, df = solr_request(
|
|
85
|
+
core='genotype-phenotype',
|
|
86
|
+
params={'q': '*:*', 'rows': 10},
|
|
87
|
+
base_url='http://solr-host:8983/solr',
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
|
|
79
91
|
## a. Facet request
|
|
80
92
|
|
|
81
93
|
`solr_request` allows facet requests
|
|
@@ -258,4 +270,4 @@ get_core_fields("genotype-phenotype")
|
|
|
258
270
|
|
|
259
271
|
The complete list is returned. An unknown core returns an empty list. Skills and
|
|
260
272
|
other integrations should call this function instead of maintaining their own
|
|
261
|
-
copies of core field names.
|
|
273
|
+
copies of core field names.
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
## Installation Instructions
|
|
6
6
|
|
|
7
|
-
0. Ensure that Python is installed on your system. The minimum required version is 3.
|
|
7
|
+
0. Ensure that Python is installed on your system. The minimum required version is 3.12.
|
|
8
|
+
Python 3.10 will not be supported after version 2.0.0.
|
|
8
9
|
|
|
9
10
|
1. **Create a virtual environment (optional but recommended)**:
|
|
10
11
|
On Mac or Linux:
|
|
@@ -59,6 +60,17 @@ num_found, df = solr_request(
|
|
|
59
60
|
)
|
|
60
61
|
```
|
|
61
62
|
|
|
63
|
+
To use another compatible Solr deployment, override the base URL. The same
|
|
64
|
+
argument is available on `batch_solr_request`:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
num_found, df = solr_request(
|
|
68
|
+
core='genotype-phenotype',
|
|
69
|
+
params={'q': '*:*', 'rows': 10},
|
|
70
|
+
base_url='http://solr-host:8983/solr',
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
62
74
|
## a. Facet request
|
|
63
75
|
|
|
64
76
|
`solr_request` allows facet requests
|
|
@@ -241,4 +253,4 @@ get_core_fields("genotype-phenotype")
|
|
|
241
253
|
|
|
242
254
|
The complete list is returned. An unknown core returns an empty list. Skills and
|
|
243
255
|
other integrations should call this function instead of maintaining their own
|
|
244
|
-
copies of core field names.
|
|
256
|
+
copies of core field names.
|
|
@@ -16,7 +16,7 @@ from impc_api.utils.warnings import (
|
|
|
16
16
|
UnsupportedDownloadFormatError,
|
|
17
17
|
LargeRequestMemoryWarning
|
|
18
18
|
)
|
|
19
|
-
from .solr_request import solr_request
|
|
19
|
+
from .solr_request import DEFAULT_SOLR_BASE_URL, solr_request
|
|
20
20
|
|
|
21
21
|
# Initialise warning config
|
|
22
22
|
warning_config()
|
|
@@ -30,6 +30,7 @@ def batch_solr_request(
|
|
|
30
30
|
download: bool = False,
|
|
31
31
|
batch_size: int = 5000,
|
|
32
32
|
filename: str = "batch_request",
|
|
33
|
+
base_url: str = DEFAULT_SOLR_BASE_URL,
|
|
33
34
|
) -> pd.DataFrame:
|
|
34
35
|
"""Function for large API requests (>1,000,000 results). Fetches the data in batches and
|
|
35
36
|
produces a Pandas DataFrame or downloads a file in json or csv formats.
|
|
@@ -42,6 +43,8 @@ def batch_solr_request(
|
|
|
42
43
|
download (bool, optional): True for download a local file, False to display results as a DataFrame. Defaults to False.
|
|
43
44
|
batch_size (int, optional): Size of batches to fetch the data. Defaults to 5000.
|
|
44
45
|
filename (str, optional): When download=True, select the name of the file. Defaults to 'batch_request'.
|
|
46
|
+
base_url (str, optional): default public IMPC Solr endpoint.
|
|
47
|
+
Override this to use another compatible Solr deployment.
|
|
45
48
|
|
|
46
49
|
|
|
47
50
|
Returns:
|
|
@@ -81,7 +84,10 @@ def batch_solr_request(
|
|
|
81
84
|
|
|
82
85
|
# Determine the total number of rows. Note that we do not request any data (rows = 0).
|
|
83
86
|
num_results, _ = solr_request(
|
|
84
|
-
core=core,
|
|
87
|
+
core=core,
|
|
88
|
+
params={**params, "start": 0, "rows": 0, "wt": "json"},
|
|
89
|
+
silent=True,
|
|
90
|
+
base_url=base_url,
|
|
85
91
|
)
|
|
86
92
|
print(f"Number of found documents: {num_results}")
|
|
87
93
|
|
|
@@ -95,7 +101,7 @@ def batch_solr_request(
|
|
|
95
101
|
# Implement loop behaviour
|
|
96
102
|
print("Downloading file...")
|
|
97
103
|
filename_path = Path(f"{filename}.{params['wt']}")
|
|
98
|
-
gen = _batch_solr_generator(core, params, num_results)
|
|
104
|
+
gen = _batch_solr_generator(core, params, num_results, base_url=base_url)
|
|
99
105
|
_solr_downloader(params, filename_path, gen)
|
|
100
106
|
print(f"File saved as: {filename_path}")
|
|
101
107
|
except UnsupportedDownloadFormatError as e:
|
|
@@ -117,11 +123,14 @@ def batch_solr_request(
|
|
|
117
123
|
message="This request may exceed available memory. If the download fails, set 'download=True' and try again.",
|
|
118
124
|
category=LargeRequestMemoryWarning,
|
|
119
125
|
)
|
|
120
|
-
return _batch_to_df(core, params, num_results)
|
|
126
|
+
return _batch_to_df(core, params, num_results, base_url=base_url)
|
|
121
127
|
|
|
122
128
|
# Helper batch_to_df
|
|
123
129
|
def _batch_to_df(
|
|
124
|
-
core: str,
|
|
130
|
+
core: str,
|
|
131
|
+
params: Dict[str, Any],
|
|
132
|
+
num_results: int,
|
|
133
|
+
base_url: str = DEFAULT_SOLR_BASE_URL,
|
|
125
134
|
) -> pd.DataFrame:
|
|
126
135
|
"""Helper function to fetch data in batches and display them in a DataFrame
|
|
127
136
|
|
|
@@ -147,6 +156,7 @@ def _batch_to_df(
|
|
|
147
156
|
core=core,
|
|
148
157
|
params={**params, "start": start, "rows": batch_size},
|
|
149
158
|
silent=True,
|
|
159
|
+
base_url=base_url,
|
|
150
160
|
)
|
|
151
161
|
|
|
152
162
|
# Update progress bar with the number of rows requested.
|
|
@@ -161,7 +171,10 @@ def _batch_to_df(
|
|
|
161
171
|
|
|
162
172
|
|
|
163
173
|
def _batch_solr_generator(
|
|
164
|
-
core: str,
|
|
174
|
+
core: str,
|
|
175
|
+
params: Dict[str, Any],
|
|
176
|
+
num_results: int,
|
|
177
|
+
base_url: str = DEFAULT_SOLR_BASE_URL,
|
|
165
178
|
) -> Iterator[BatchSolrChunk]:
|
|
166
179
|
"""Generator function to fetch results from the SOLR API in batches using pagination.
|
|
167
180
|
|
|
@@ -176,8 +189,7 @@ def _batch_solr_generator(
|
|
|
176
189
|
Yields:
|
|
177
190
|
([dict, str]): A JSON object or plain text with the results.
|
|
178
191
|
"""
|
|
179
|
-
|
|
180
|
-
solr_url = base_url + core + "/select"
|
|
192
|
+
solr_url = f"{base_url.rstrip('/')}/{core}/select"
|
|
181
193
|
start = params["start"]
|
|
182
194
|
batch_size = params["rows"]
|
|
183
195
|
|
|
@@ -13,6 +13,7 @@ SolrRequestResult = Optional[
|
|
|
13
13
|
]
|
|
14
14
|
|
|
15
15
|
DEFAULT_REQUEST_TIMEOUT: RequestTimeout = 10.0
|
|
16
|
+
DEFAULT_SOLR_BASE_URL = "https://www.ebi.ac.uk/mi/impc/solr/"
|
|
16
17
|
|
|
17
18
|
# Display the whole dataframe <15
|
|
18
19
|
pd.set_option("display.max_rows", 15)
|
|
@@ -26,6 +27,7 @@ def solr_request(
|
|
|
26
27
|
validate: bool = False,
|
|
27
28
|
url_only: bool = False,
|
|
28
29
|
timeout: RequestTimeout = DEFAULT_REQUEST_TIMEOUT,
|
|
30
|
+
base_url: str = DEFAULT_SOLR_BASE_URL,
|
|
29
31
|
) -> SolrRequestResult:
|
|
30
32
|
"""Performs a single Solr request to the IMPC Solr API.
|
|
31
33
|
|
|
@@ -42,6 +44,8 @@ def solr_request(
|
|
|
42
44
|
If true, returns the request URL but no data.
|
|
43
45
|
timeout (int or float, optional): default 10
|
|
44
46
|
Number of seconds to wait for the API request before timing out.
|
|
47
|
+
base_url (str, optional): default public IMPC Solr endpoint.
|
|
48
|
+
Override this to use another compatible Solr deployment.
|
|
45
49
|
|
|
46
50
|
|
|
47
51
|
Returns:
|
|
@@ -95,8 +99,7 @@ def solr_request(
|
|
|
95
99
|
if validate:
|
|
96
100
|
CoreParamsValidator(core=core, params=params)
|
|
97
101
|
|
|
98
|
-
|
|
99
|
-
solr_url = base_url + core + "/select"
|
|
102
|
+
solr_url = f"{base_url.rstrip('/')}/{core}/select"
|
|
100
103
|
|
|
101
104
|
response = requests.get(solr_url, params=params, timeout=timeout)
|
|
102
105
|
|
|
@@ -176,7 +179,10 @@ def _process_faceting(data: Dict[str, Any], params: Dict[str, Any]) -> pd.DataFr
|
|
|
176
179
|
|
|
177
180
|
# Batch request based on solr_request.
|
|
178
181
|
def batch_request(
|
|
179
|
-
core: str,
|
|
182
|
+
core: str,
|
|
183
|
+
params: Dict[str, Any],
|
|
184
|
+
batch_size: int,
|
|
185
|
+
base_url: str = DEFAULT_SOLR_BASE_URL,
|
|
180
186
|
) -> pd.DataFrame:
|
|
181
187
|
"""Calls `solr_request` multiple times with `params`
|
|
182
188
|
to retrieve results in chunk `batch_size` rows at a time.
|
|
@@ -186,7 +192,8 @@ def batch_request(
|
|
|
186
192
|
Args:
|
|
187
193
|
core (str): name of IMPC solr core.
|
|
188
194
|
params (dict): dictionary containing the API call parameters.
|
|
189
|
-
|
|
195
|
+
batch_size (int): Size of batches (number of docs) per request.
|
|
196
|
+
base_url (str, optional): default public IMPC Solr endpoint.
|
|
190
197
|
|
|
191
198
|
Returns:
|
|
192
199
|
pandas.DataFrame: Pandas.DataFrame object with the information requested.
|
|
@@ -208,7 +215,10 @@ def batch_request(
|
|
|
208
215
|
)
|
|
209
216
|
# Determine the total number of rows. Note that we do not request any data (rows = 0).
|
|
210
217
|
num_results, _ = solr_request(
|
|
211
|
-
core=core,
|
|
218
|
+
core=core,
|
|
219
|
+
params={**params, "start": 0, "rows": 0},
|
|
220
|
+
silent=True,
|
|
221
|
+
base_url=base_url,
|
|
212
222
|
)
|
|
213
223
|
# Initialise everything for data retrieval.
|
|
214
224
|
start = 0
|
|
@@ -223,6 +233,7 @@ def batch_request(
|
|
|
223
233
|
core=core,
|
|
224
234
|
params={**params, "start": start, "rows": batch_size},
|
|
225
235
|
silent=True,
|
|
236
|
+
base_url=base_url,
|
|
226
237
|
)
|
|
227
238
|
# Record chunk.
|
|
228
239
|
chunks.append(df_chunk)
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "impc_api"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.1.0"
|
|
8
8
|
description = "A package to facilitate making API requests to the IMPC Solr API"
|
|
9
9
|
license = "Apache-2.0"
|
|
10
10
|
license-files = ["LICENSE"]
|
|
@@ -23,7 +23,7 @@ dependencies = [
|
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
readme = "README.md"
|
|
26
|
-
requires-python = ">=3.
|
|
26
|
+
requires-python = ">=3.12"
|
|
27
27
|
|
|
28
28
|
[dependency-groups]
|
|
29
29
|
dev = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|