Skip to main content

Fast-API Response catalog for pre-computed query

Project description

Akvo-ResponseGrouper

PyPI Build Status Repo Size Coverage Status Languages Issues Last Commit Documentation Status GitHub license

Fast-API Response catalog for pre-computed query

Install

$ pip install AkvoResponseGrouper

Schema Requirements

Please follow the required schema before using AkvoResponseGrouper.

Usage

  1. Database Migration

Database migration is the first required step for AkvoResponseGrouper to work. Use the akvo-responsegrouper CLI to migrate all data sources with JSON configuration files to generate Materialized Views that AkvoResponseGrouper can then use.

$ akvo-responsegrouper
usage: akvo-responsegrouper [-h] [-c CONFIG] [-d]

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        akvo-responsegrouper -c <json_file_config>
  -d, --drop            Drop the ar_category view table
  1. Router

To get the new endpoint provided by AkvoResponseGrouper, import the collection route to the App by:

from fastapi import FastAPI
from AkvoResponseGrouper.routes import collection_route

app = FastAPI(
    root_path="/",
    title="Akvo Response Grouper Demo",
)

app.include_router(collection_route)

@app.get("/", tags=["Dev"])
def read_main():
    return "OK"
  1. Query

Development

Run Dev Containers

The dev environment contains two containers: FastAPI backend and PostGres db, to run:

docker compose up -d

Before go to the next step, wait until the service started at http://localhost:5000.

Seed Necessary Data

In order to debug the data itself. We need to seed the example form and fake datapoints

docker compose exec backend python -m script.seeder_form
docker compose exec backend python -m script.seeder_datapoint <number_of_datapoint>

Migration

Dev environment uses contents that is available in Akvo-ResponseGrouper/src/AkvoResponseGrouper. To create the Category Materialized View via CLI in dev environment:

Upgrade:

python -m AkvoResponseGrouper.cli.migrate -c './sources/category.json'

After upgrade, you can see "AkvoResponseGrouper - Collection" is available in API docs, ussualy http://locahhost:5000/docs (Depends on the root path api).

Downgrade:

python -m AkvoResponseGrouper.cli.migrate -c './sources/category.json'

Teardown

docker compose down -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

AkvoResponseGrouper-1.2.0.tar.gz (25.2 kB view hashes)

Uploaded Source

Built Distribution

AkvoResponseGrouper-1.2.0-py3-none-any.whl (26.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page