Api
Settings
Bases: BaseSettings
anystore settings management using
pydantic-settings
Note
All settings can be set via environment variables in uppercase,
prepending FTMQ_API_ (except for those with a given prefix)
Source code in ftmq/api/settings.py
allowed_origin = ['http://localhost:3000']
class-attribute
instance-attribute
Allowed origins
build_api_key = 'secret-key-for-build'
class-attribute
instance-attribute
Backend api key to use for build process (higher limit)
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 public pagination limit
info = ApiInfo()
class-attribute
instance-attribute
Rendered information on redoc page
min_search_length = 3
class-attribute
instance-attribute
Minimum search query length
store_uri = DB_URL
class-attribute
instance-attribute
ftmq store uri
use_cache = False
class-attribute
instance-attribute
Activate caching
View
A wrapper around a store's default View scoped
to the api's use cases.
Source code in ftmq/api/store.py
build_query(request, authenticated=False)
Build a Query from a request's query params.
The flat filter grammar is the Aleph one (filter: / exclude: /
empty:, sort, limit / offset, metric:<func> / facet) parsed via
Query.from_params. An optional rql= param
carries a full nested RQL filter tree (and, if
present, its aggregations); it overrides the flat filter grammar while
sort / limit / offset keep coming from the plain params.
Non-query params (q, api_key, retrieve flags) are ignored by the
parser. The limit is capped to settings.default_limit unless the request
is authenticated; datasets are validated against the catalog.
Raises:
| Type | Description |
|---|---|
HTTPException
|
422 for a dataset not in the catalog. |
QueryError
|
For invalid filter fields, values or RQL (handled as 400 upstream). |
Source code in ftmq/api/query.py
params_from_request(request)
Collect the request query params as a dict of lists (starlette's
QueryParams.items() drops repeated keys).
Source code in ftmq/api/query.py
serialization data models as seen in https://github.com/opensanctions/yente/
EntitiesResponse
Bases: BaseModel
The list / search response, matching the OpenAleph api v2 envelope.
Source code in ftmq/api/serialize.py
build_facets(aggregations)
Grouped aggregations as Aleph-style facets:
{field: {"values": [{"value", "label", <func>: value}], "total": n}}.
A count grouping yields the idiomatic Aleph {value, label, count}; other
functions ride under their function name in each value bucket.
Source code in ftmq/api/serialize.py
build_filters(query)
The applied positive filters as {field: [values]} (empty for nested queries).
Source code in ftmq/api/serialize.py
build_metrics(aggregations)
Ungrouped aggregations as Aleph-style metrics: {prop: {func: value}}.