This PoC is using FastAPI with SQLAlchemy, to:
Helpful for a cronjob/task that triggers every 5 minutes the endpoint “/cronjob/{item_id}” It will check if it’s a new Spreadsheet or already exists. In the first case it will create a new RECORD inside the TABLE data, otherwise it will update the existing TABLE items with the new items.
REST API access to items resources.
Action | HTTPVerb | Endpoint | Description |
---|---|---|---|
Fetch | GET | /fetch/{item_id} | Fetch All Items in realtime from Google Sheet [for debug] |
Cronjob | POST/PUT | /cronjob/{item_id} | Fetch All Items From Google And Store/Update DB |
Query | GET | /query | Get items from the DB based on Google ID |
There are 3 differents setup to run this project:
SETUP A LOCAL PYTHON ENV
$ git clone git@github.com:garanet/fastapi_sqlalchemy.git
$ cd fastapi_sqlalchemy
$ pipenv shell --python 3.11
$ pipenv install google-api-python-client
$ pipenv install google-auth-httplib2
$ pipenv install google-auth-oauthlib
$ pipenv install fastapi
$ pipenv install uvicorn
$ pipenv install sqlalchemy
$ pipenv install pandas
or
$ pip install -r requiremets.txt
$ cp ~/Download/credentials.json ./app/config/
$ python main.py
SETUP A DOCKER ENV
$ git clone git@github.com:garanet/fastapi_sqlalchemy.git
$ cd fastapi_sqlalchemy
$ cp ~/Download/credentials.json ./app/config/
$ docker build -t fastapi:latest .
$ docker run -p 9000:9000 fastapi
SETUP A K8s ENV with microk8s
$ git clone git@github.com:garanet/fastapi_sqlalchemy.git
$ cd fastapi_sqlalchemy
$ cp ~/Download/credentials.json ./app/config/
$ docker build -t fastapi:latest .
$ docker save fastapi:latest > fastapi.tar
$ microk8s ctr image import fastapi.tar
$ flux reconcile ks microservices
GET /fetch/{item_id} -> "Get items from Google without store them"
$ curl -X 'GET' \ 'http://127.0.0.1:9000/fetch/{google_spreadsheet_id}' \latest.tar -H 'accept: application/json'
POST /cronjob/{item_id} -> "Get items and store or update them into the DB"
$ curl -X 'POST' \ 'http://127.0.0.1:9000/cronjob?item_id=1LAvH4wPOXZSdfVRRHwDGaS5ensyQg2TNm_eoISNcnQg' \ -H 'accept: application/json' \ -d ''
GET /querey/{item_id} -> "Get items from the DB"
$ curl -X 'GET' \ 'http://127.0.0.1:9000/query?item_id=1LAvH4wPOXZSdfVRRHwDGaS5ensyQg2TNm_eoISNcnQg' \ -H 'accept: application/json'
Google Cloud Console
Follow these docs to generate the credentials.json file
The full repository and the code explanation, visit my GITHUB
A webtool in Python Flask that creates an LDAP user and his TrueNAS shares pool in ISCSI or NFS. There… Read More
A Terraform configuration that provisions the following infrastructure: A VPC with: Public subnets for external resources. Private subnets for internal… Read More
Kubernetes is an open-source container orchestration tool or system that is used to automate tasks Read More
This website uses cookies.
Read More