api.server
This module house the HTTP wrapper. Since most call signature and return values are fastapi standard, they will not be included.
The names of functions will be reflective if their purpose:
middleware_*
get_*
exception_*
api
EndpointLoggingFilter
Custom logger filter. Do not log metrics, ready endpoint.
Source code in api/server/api.py
exception_runtime(request, exc)
async
Handling RuntimeErrors. Most of the RuntimeErrors are thrown by the siibra-python library when other Services are not responding. To be more resilient and not throw a simple and unplanned HTTP 500 response, this handler will return an HTTP 503 status.
Source code in api/server/api.py
exception_sapi(request, exc)
Handle sapi errors
exception_other(request, exc)
async
Catch all exception handler
Source code in api/server/api.py
middleware_cache_response(request, call_next)
async
Cache requests to redis, to improve response time.
Source code in api/server/api.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
middleware_get_python_code(request, call_next)
async
If Accept header is set to text/x-sapi-python, return the python code as plain text response.
Source code in api/server/api.py
middleware_add_version_header(request, call_next)
async
Add siibra-api version as a custom header
Source code in api/server/api.py
middleware_access_log(request, call_next)
async
Access log middleware
Source code in api/server/api.py
get_home(request)
Return the template for the siibra landing page.
Source code in api/server/api.py
get_metrics()
cache
DummyCache
get_instance()
Get the store singleton
Source code in api/server/cache/__init__.py
on_startup()
terminate()
redis
_is_ci = IS_CI
module-attribute
Do not use cache if IS_CI set via config
CacheGzipRedis
GzipRedis. This store gzip then b64 encode the gzipped result.
Source code in api/server/cache/redis.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
get_value(key)
Get stored value acording to key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
str |
required |
Returns:
Type | Description |
---|---|
str
|
stored value |
Source code in api/server/cache/redis.py
getstr(val)
staticmethod
Convert str|bytes into str
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Union[str, bytes]
|
value to be stringified |
required |
Returns:
Type | Description |
---|---|
str
|
string in utf-8 encoding |
Raises:
Type | Description |
---|---|
Exception
|
neither str or bytes are provided |
Source code in api/server/cache/redis.py
getbytes(val)
staticmethod
Convert str|bytes into bytes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Union[str, bytes]
|
value to be stringified |
required |
Returns:
Type | Description |
---|---|
bytes
|
bytes |
Raises:
Type | Description |
---|---|
Exception
|
neither str or bytes are provided |
Source code in api/server/cache/redis.py
decode(val)
staticmethod
decode gzipped b64 encoded string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Union[str, bytes]
|
value to be decoded |
required |
Returns:
Type | Description |
---|---|
str
|
decoded value |
Source code in api/server/cache/redis.py
encode(val)
staticmethod
encode value into gzipped b64
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Union[str, bytes]
|
value to be encoded |
required |
Returns:
Type | Description |
---|---|
str
|
string representing gzipped, b64 of the original string |
Source code in api/server/cache/redis.py
on_startup()
On startup call
Source code in api/server/cache/redis.py
code_snippet
get_source_from_fn(fn)
Gets the all functions in a closure
Source code in api/server/code_snippet.py
lookup_handler_fn(arm, scope)
Lookup (recursively if necessary) to find the Route responsible for a given scope.
Source code in api/server/code_snippet.py
get_sourcecode(request)
Process a request, and transform it into the corresponding Python snippet
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Request
|
Request |
required |
Returns:
Type | Description |
---|---|
str
|
python snippet |
Source code in api/server/code_snippet.py
compounds
download
router = APIRouter(route_class=SapiCustomRoute, tags=['download'])
module-attribute
HTTP download bundle router
cleanup(filepath)
get_download_bundle(space_id, parcellation_id, bbox=None, region_id=None, feature_id=None, *, background, func)
Prepare the bundle. Given a specification, prepare/bundle according to the specification.
Source code in api/server/compounds/download.py
get_download_progress(task_id)
Get download task progress with task_id
Source code in api/server/compounds/download.py
get_download_result(task_id, background)
Download the bundle
Source code in api/server/compounds/download.py
const
FASTAPI_VERSION = (3, 0)
module-attribute
siibra-api version
core
atlas
TAGS = ['atlas']
module-attribute
HTTP atlas routes tags
router = APIRouter(route_class=SapiCustomRoute)
module-attribute
HTTP atlas routes router
get_all_atlases(*, func)
HTTP get all atlases
Source code in api/server/core/atlas.py
get_single_atlas(atlas_id, *, func)
HTTP get a single atlas
Source code in api/server/core/atlas.py
parcellation
TAGS = ['parcellation']
module-attribute
HTTP parcellation routes tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP parcellation routes router
get_all_parcellations(func)
HTTP get all parcellations
Source code in api/server/core/parcellation.py
get_single_parcellation(parcellation_id, *, func)
HTTP get a single parcellation
Source code in api/server/core/parcellation.py
region
TAGS = ['region']
module-attribute
HTTP region routes tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP region routes router
get_all_regions(parcellation_id, find=None, func=lambda: [])
HTTP get all regions
Source code in api/server/core/region.py
get_all_features_region(parcellation_id, region_id, func=lambda: [])
HTTP get all features of a single region
Source code in api/server/core/region.py
get_related_region(parcellation_id, region_id, func=lambda: [])
HTTP get_related_regions of the specified region
Source code in api/server/core/region.py
get_single_regions(parcellation_id, region_id, space_id=None, func=lambda: None)
HTTP get a single region
Source code in api/server/core/region.py
space
TAGS = ['space']
module-attribute
HTTP space routes tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP space routes router
get_all_spaces(*, func)
HTTP get all spaces
Source code in api/server/core/space.py
get_single_space(space_id, *, func)
HTTP get a single space
Source code in api/server/core/space.py
features
TAGS = ['feature']
module-attribute
HTTP feature tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP feature router
FeatureMetaModel
Meta feature type
Source code in api/server/features/__init__.py
CategoryModel
depascal(input)
Pascal to snake
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
str
|
string in PascalCase |
required |
Returns:
Type | Description |
---|---|
str
|
string in snake_case |
Source code in api/server/features/__init__.py
retrieve_routes(request, feature_name)
Retrieve the meta info on feature types, given feature_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_name |
str
|
feature identifier (e.g. name) |
required |
Returns:
Type | Description |
---|---|
Dict
|
Meta info |
Source code in api/server/features/__init__.py
get_all_feature_types(request, func)
Get meta info of all feature types
Source code in api/server/features/__init__.py
get_all_connectivity_features(parcellation_id, type=None, func=lambda: [])
async
Get all connectivity features
Source code in api/server/features/__init__.py
get_single_connectivity_feature(parcellation_id, feature_id, subject=None, type=None, func=lambda: None)
async
Get single connectivity feature
Source code in api/server/features/__init__.py
get_all_corticalprofile_features(parcellation_id, region_id, type=None, func=lambda: [])
async
Get all CorticalProfile features
Source code in api/server/features/__init__.py
get_single_corticalprofile_feature(parcellation_id, region_id, feature_id, type=None, func=lambda: None)
async
Get a single CorticalProfile feature
Source code in api/server/features/__init__.py
get_all_tabular(parcellation_id, region_id, type=None, func=lambda: [])
async
Get all tabular features
Source code in api/server/features/__init__.py
get_single_tabular(parcellation_id, region_id, feature_id, type=None, func=lambda: None)
async
Get a single tabular feature
Source code in api/server/features/__init__.py
get_all_voi(space_id, bbox=None, type=None, func=lambda: [])
async
Get all Image features
Source code in api/server/features/__init__.py
get_single_voi(space_id, feature_id, type=None, func=lambda: [])
async
Get a single Image feature
Source code in api/server/features/__init__.py
get_all_gene(parcellation_id, region_id, gene, func=lambda: [])
async
Get all GeneExpressions features
Source code in api/server/features/__init__.py
get_single_gene(parcellation_id, region_id, feature_id, gene, func=lambda: [])
async
Get a single GeneExpressions feature
Source code in api/server/features/__init__.py
get_all_ebrains_df(parcellation_id, region_id, func=lambda: [])
async
Get all EbrainsDataFeatures
Source code in api/server/features/__init__.py
get_single_ebrains_df(parcellation_id, region_id, feature_id, func=lambda: None)
async
Get a single EbrainsDataFeature
Source code in api/server/features/__init__.py
get_single_feature(feature_id, request, func)
async
Get a single feature, from feature_id
Source code in api/server/features/__init__.py
get_single_feature_plot(feature_id, request, func, template=PlotlyTemplate.plotly)
async
Get plotly spec from feature_id
Source code in api/server/features/__init__.py
get_single_feature_download(feature_id, request, func)
async
Get download zip
Source code in api/server/features/__init__.py
util
wrap_feature_category(feature_category)
Wrap feature category
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_category |
str
|
string representing the type to be passed as keyword argument |
required |
Source code in api/server/features/util.py
metrics
Singleton
Timer singleton
Source code in api/server/metrics.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
refresh_metric()
staticmethod
Refresh metrics.
Source code in api/server/metrics.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
on_startup()
On startup
Source code in api/server/metrics.py
on_terminate()
prom_metrics_resp()
Return PlainTextResponse of metrics
Source code in api/server/metrics.py
util
SapiCustomRoute
SapiCustomRoute, custom route class. This is so that func
param is not interpreted to be a part of swagger-api.
Source code in api/server/util.py
add_lazy_path()
adds lazy_path path converter for starlette route
For example:
GET /atlases/juelich%2Fiav%2Fatlas%2Fv1.0.0%2F1/parcellations/minds%2Fcore%2Fparcellationatlas%2Fv1.0.0%2F94c1125b-b87e-45e4-901c-00daee7f2579-290/regions/Area%20hOc1%20%28V1%2C%2017%2C%20CalcS%29%20right/features/siibra%2Ffeatures%2Fcells%2Fhttps%3A%2F%2Fopenminds.ebrains.eu%2Fcore%2FDatasetVersion%2Fc1438d1996d1d2c86baa05496ba28fc5
or
"/atlases/{atlas_id}/parcellations/{parc_id}/regions/{region_id}/features/{feat_id}".format(
atlas_id="juelich%2Fiav%2Fatlas%2Fv1.0.0%2F1",
parc_id="minds%2Fcore%2Fparcellationatlas%2Fv1.0.0%2F94c1125b-b87e-45e4-901c-00daee7f2579-290",
region_id="Area%20hOc1%20%28V1%2C%2017%2C%20CalcS%29%20right",
feat_id="siibra%2Ffeatures%2Fcells%2Fhttps%3A%2F%2Fopenminds.ebrains.eu%2Fcore%2FDatasetVersion%2Fc1438d1996d1d2c86baa05496ba28fc5",
)
default path converter (eager) will:
1/ deserialize URI encoded characters, resulting in:
"/atlases/{atlas_id}/parcellations/{parc_id}/regions/{region_id}/features/{feat_id}".format(
atlas_id="juelich/iav/atlas/v1.0.0/1",
parc_id="minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290",
region_id="Area hOc1 (V1, 17, CalcS) right",
feat_id="siibra/features/cells/https://openminds.ebrains.eu/core/DatasetVersion/c1438d1996d1d2c86baa05496ba28fc5",
)
2/ try to eager match, resulting in errorenous parsing of the path:
"/atlases/{atlas_id}/parcellations/{parc_id}/regions/{region_id}/features/{feat_id}".format(
atlas_id="juelich/iav/atlas/v1.0.0/1",
parc_id="minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290",
region_id="Area hOc1 (V1, 17, CalcS) right/features/siibra",
feat_id="cells/https://openminds.ebrains.eu/core/DatasetVersion/c1438d1996d1d2c86baa05496ba28fc5",
)
The lazy path converter is not without its (potential) issue:
For example:
"GET /atlases/foo-bar/parcellations/parc%2Ffeatures%2Ffoo/features"
or
"/atlases/{atlas_id}/parcellations/{parc_id}/features".format(
atlas_id="foo-bar",
parc_id="parc%2Ffeatures%2Ffoo"
)
1/ deserialization of URI encoded characters, resulting in:
"/atlases/{atlas_id}/parcellations/{parc_id}/features".format(
atlas_id="foo-bar",
parc_id="parc/features/foo"
)
2/ trying to lazy match, resulting in errorenous parsing of the path:
"/atlases/{atlas_id}/parcellations/{parc_id}/features/{features_id}".format(
atlas_id="foo-bar",
parc_id="parc",
features_id="foo"
)
Most ideally, the starlette routing should split path first, then decode the encoded characters
Source code in api/server/util.py
volcabularies
TAGS = ['vocabularies']
module-attribute
HTTP vocabularies tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP vocabularies router
genes(find=None, func=None)
HTTP get (filtered) genes
Source code in api/server/volcabularies/__init__.py
volumes
maps
TAGS = ['maps']
module-attribute
HTTP map tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP map router
filter_map(parcellation_id=None, space_id=None, map_type=None, *, func)
Get a list of maps according to specification
Source code in api/server/volumes/maps.py
single_map(map_id, *, func)
Get a list of maps according to specification
Source code in api/server/volumes/maps.py
parcellationmap
TAGS = ['maps']
module-attribute
HTTP map tags
router = APIRouter(route_class=SapiCustomRoute, tags=TAGS)
module-attribute
HTTP map router
get_siibra_map(parcellation_id, space_id, map_type, *, func)
Get map according to specification.
Deprecated. use /maps/{map_id} instead.
Source code in api/server/volumes/parcellationmap.py
get_resampled_map(parcellation_id, space_id, name='', *, func)
Get resampled map according to specification
Source code in api/server/volumes/parcellationmap.py
get_parcellation_labelled_map(parcellation_id, space_id, region_id=None, *, func)
Get labelled map according to specification
Source code in api/server/volumes/parcellationmap.py
get_region_statistical_map(parcellation_id, region_id, space_id, name='', *, func)
Get statistical map according to specification
Source code in api/server/volumes/parcellationmap.py
get_region_statistical_map_metadata(parcellation_id, region_id, space_id, name='', *, func)
Get metadata of statistical map according to specification
Source code in api/server/volumes/parcellationmap.py
get_assign_point(parcellation_id, space_id, point, assignment_type='statistical', sigma_mm=0.0, *, func)
Perform assignment according to specification