ftmq.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 = None
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
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
nomenklatura resolver uri: a sql database holding 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.
settings.catalog describes datasets, but the store decides which
exist. A name present in the store and missing from the catalog is added
as a bare dataset, so a catalog naming something else - or no catalog at
all - can never leave the store's own datasets un-queryable (the dataset
filter validates against this catalog).
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
The response-shaping query params (a Depends() dependency).
Source code in ftmq/api/query.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 and its select projection); 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 and each facet
size to settings.max_facet_size, 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
EntityResponse
build_facets(aggregations, query)
Grouped aggregations as Aleph facets with buckets of
{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 applied 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 an entity count per facet, so every bucket has its count, and the
facet's distinct values, its 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.