3.6. Query - tjmisko/sspi-data-webapp GitHub Wiki

Query

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>

Details and Notes

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.

  1. 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.
  1. 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.
  2. The --limit or -l flag caps the number of documents returned. Useful for large datasets or testing.
  3. The --remote or -r flag directs the request to the deployed remote server (https://sspi.world/) instead of the local development server.

Example Usages

Query the raw data collected for one dataset:

sspi query sspi_raw_api_data UNSDG_TERRST

Query multiple datasets with a result limit:

sspi query sspi_clean_api_data UNSDG_TERRST UNSDG_FRSHWT --limit 5

Query the same datasets from the remote server:

sspi query sspi_clean_api_data UNSDG_TERRST --remote

Notes for Developers

  • The query command is implemented in the CLI module under cli/commands/query.py; the backend route is implemented in sspi_flask_app/api/core/query.py

  • It constructs the corresponding REST API endpoint dynamically from user inputs:

    request_string = f"/api/v1/query/{database}?"
  • SSPIDatabaseConnector handles 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.

⚠️ **GitHub.com Fallback** ⚠️