ftmq.api
Settings
Bases: BaseSettings
Api settings, read from FTMQ_API_ prefixed environment variables.
Nested fields join with _, e.g. FTMQ_API_INFO_TITLE.
Source code in ftmq/api/settings.py
allowed_origin = ['http://localhost:3000']
class-attribute
instance-attribute
Allowed CORS origins
build_api_key = None
class-attribute
instance-attribute
Api key that lifts the public limits (e.g. for build processes)
cache = StoreModel(uri='.cache', backend_config={'redis_prefix': f'ftmq-api/{__version__}'})
class-attribute
instance-attribute
Api cache (via anystore)
catalog = None
class-attribute
instance-attribute
Catalog uri
default_limit = 100
class-attribute
instance-attribute
Default and public maximum page size
info = ApiInfo()
class-attribute
instance-attribute
ReDoc page information
max_facet_size = 50
class-attribute
instance-attribute
Public cap on the buckets per facet
min_search_length = 3
class-attribute
instance-attribute
Minimum search query length
resolver_uri = None
class-attribute
instance-attribute
Resolver uri (a sql database with a resolver table, or a json lines edge
dump); defaults to the store uri
store_uri = DB_URL
class-attribute
instance-attribute
ftmq store uri
use_cache = False
class-attribute
instance-attribute
Activate caching
get_catalog()
cached
The catalog of queryable datasets, reconciled with the store.
A dataset in the store but missing from settings.catalog is added as a
bare entry, so every stored dataset is queryable.
Source code in ftmq/api/store.py
get_entity(entity_id, params)
The entity by id, or by a referent id the store's linker resolves.
Source code in ftmq/api/store.py
get_store_datasets()
The dataset names the configured store actually holds.
Source code in ftmq/api/store.py
shape(proxy, params)
Dehydrate an entity, or reduce it to its featured properties, as asked.
Source code in ftmq/api/store.py
RetrieveParams
dataclass
Response-shaping query params (a FastAPI Depends() dependency).
Source code in ftmq/api/query.py
build_query(request, authenticated=False)
Build a Query from a request's query params.
The params are parsed via Query.from_params; an
optional rql= param (Query.from_rql) replaces the
filter tree (and the aggregations / projection, if it carries any). Unless
authenticated, the limit is capped to settings.default_limit and each facet
size to settings.max_facet_size.
Raises:
| Type | Description |
|---|---|
HTTPException
|
422 for a dataset not in the catalog. |
QueryError
|
For an invalid field, value or RQL string. |
Source code in ftmq/api/query.py
params_from_request(request)
The request query params as a dict of lists, keeping repeated keys.
Source code in ftmq/api/query.py
Api response models, modelled on yente.
EntitiesResponse
Bases: BaseModel
The list / search response, matching the OpenAleph api v2 envelope.
Source code in ftmq/api/serialize.py
EntityResponse
build_facets(aggregations, query)
The grouped aggregations as Aleph facets.
Buckets are {value, label, count, metrics: {field: {func: value}}}, ranked
by the query's facet_sort metric, else by entity count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregations
|
AggregatorResult
|
The computed aggregations, with bucket counts. |
required |
query
|
Query
|
The request query. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The Aleph-style |
Source code in ftmq/api/serialize.py
build_filters(query)
The positive filters as {field: [values]} (empty for nested queries).
Source code in ftmq/api/serialize.py
build_metrics(aggregations, query)
The query's ungrouped aggregations as {field: {func: value}}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregations
|
AggregatorResult
|
The computed aggregations. |
required |
query
|
Query
|
The request query; only its aggregations are reported. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The Aleph-style |
Source code in ftmq/api/serialize.py
with_bucket_counts(query)
Add the counts behind each facet bucket's count and the facet's total.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Query
|
The request query. |
required |
Returns:
| Type | Description |
|---|---|
Query
|
The query to compute the aggregations with. |
Source code in ftmq/api/serialize.py
get_nested(view, entities, params)
The entities the given ones reference, to inline with nested=true.