3.6. Query - tjmisko/sspi-data-webapp GitHub Wiki
Input: Database, (optional) SeriesCode(s)
Behavior: Queries a database for specific datasets or items, returning stored data from either the local or remote SSPI server.
Output: JSON-formatted Query Result
Command:
sspi query [Database] [SeriesCode(s)] [--limit N] [--remote]Local URL:
http://localhost:5000/api/v1/query/<Database>?SeriesCode=<SeriesCode>&limit=<N>
Remote URL:
https://sspi.world/api/v1/query/<Database>?SeriesCode=<SeriesCode>&limit=<N>
A query route allows you to inspect or extract data that has already been collected and stored in one of the SSPI databases.
It is typically used to confirm the contents of a collection, check dataset completeness, or fetch results for downstream analysis.
All responses are JSON-encoded, printed directly to standard output. Use jq or similar tools to pretty-print and explore results.
- The first argument,
Database, specifies which MongoDB collection to query. Common examples include:
-
sspi_raw_api_data: Raw, unprocessed data directly from the source APIs. -
sspi_clean_api_data: Data after basic validation, parsing, and normalization. -
sspi_metadata: Metadata tables that define dataset relationships and dependencies.
- The second argument, one or more
SeriesCodes, restricts the query to the listed datasets. If none are provided, the query will return all entries in the specified database. - The
--limitor-lflag caps the number of documents returned. Useful for large datasets or testing. - The
--remoteor-rflag directs the request to the deployed remote server (https://sspi.world/) instead of the local development server.
Query the raw data collected for one dataset:
sspi query sspi_raw_api_data UNSDG_TERRSTQuery multiple datasets with a result limit:
sspi query sspi_clean_api_data UNSDG_TERRST UNSDG_FRSHWT --limit 5Query the same datasets from the remote server:
sspi query sspi_clean_api_data UNSDG_TERRST --remote-
The query command is implemented in the CLI module under
cli/commands/query.py; the backend route is implemented insspi_flask_app/api/core/query.py -
It constructs the corresponding REST API endpoint dynamically from user inputs:
request_string = f"/api/v1/query/{database}?"
-
SSPIDatabaseConnectorhandles all HTTP communication, managing timeouts and remote/local routing. -
Queries return the exact JSON output provided by the API—no post-processing or filtering occurs client-side.