pipenv shell
python3 run.py
Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.
You can find an in-depth article on this implementation here.
We encourage you to contribute to Flask Boilerplate! Please check out the Contributing guidelines about how to proceed.
- Python 3.11.3 or higher
- Up and running Redis client
# clone the repo
$ git clone https://github.com/idris-rampurawala/flask-boilerplate.git
# move to the project folder
$ cd flask-boilerplate
If you want to install redis via docker
$ docker run -d --name="flask-boilerplate-redis" -p 6379:6379 redis
- Install
pipenv
a global python projectpip install pipenv
- Create a
virtual environment
for this project
# creating pipenv environment for python 3
$ pipenv --three
# activating the pipenv environment
$ pipenv shell
# install all dependencies (include -d for installing dev dependencies)
$ pipenv install -d
# if you have multiple python 3 versions installed then
$ pipenv install -d --python 3.11
- There are 3 configurations
development
,staging
andproduction
inconfig.py
. Default isdevelopment
- Create a
.env
file from.env.example
and set appropriate environment variables before running the project
- Run flask app
python run.py
- Logs would be generated under
log
folder
- Run redis locally before running celery worker
- Celery worker can be started with following command
# run following command in a separate terminal
$ celery -A celery_worker.celery worker --loglevel='INFO'
# (append `--pool=solo` for windows)
Includes preconfigured packages to kick start flask app by just setting appropriate configuration.
Package | Usage |
---|---|
celery | Running background tasks |
redis | A Python Redis client for caching |
flask-cors | Configuring CORS |
python-dotenv | Reads the key-value pair from .env file and adds them to environment variable. |
marshmallow | A package for creating Schema, serialization, deserialization |
webargs | A Python library for parsing and validating HTTP request objects |
autopep8
& flake8
as dev
packages for linting and formatting
Test if this app has been installed correctly and it is working via following curl commands (or use in Postman)
- Check if the app is running via
status
API
$ curl --location --request GET 'http://localhost:5000/status'
- Check if core app API and celery task is working via
$ curl --location --request GET 'http://localhost:5000/api/v1/core/test'
- Check if authorization is working via (change
API Key
as per you.env
)
$ curl --location --request GET 'http://localhost:5000/api/v1/core/restricted' --header 'x-api-key: 436236939443955C11494D448451F'
Base path for all APIs: https://api.kleo.network/
- Get user details from solana address[signup/login]
path | api/v1/core/user/create-user |
Type | POST |
Description | To fetch user details from the DB |
Header | No header |
Path Variable | No |
No | Param name | type | Description | Required |
1 | Address | String | Solana address of the user | True |
2 | signup | Boolean | Flag for the user creation for signup | False |
1. | Sign up | {
“address”: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK” “signup”: true } |
2. | Login | {
“address”: “DRerVGgicvGkF7BRfyK8qguA6ycoXMcgw7usvLBhdEDC” } |
No | Status Code | Response |
1. | 200 | {
address: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”, name: “” verified: false last_cards_marked: 0 about: “” pfp: “” content_tags: [] last_attested: 0 identity_tags: [] badges: [] Profile_metadata: {} }, { address: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”, name: “Mark Status”, verified: false last_cards_marked: 1703721486 about: “Exploring the world of Solana and building cool projects” pfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg” content_tags: [ “solana”, “nft” ] last_attested: 1703721486 identity_tags: [“developer”, “SDE”] Badges: [“bonk] Profile_metadata: {} } |
2. | 400 | {"error": "Missing required parameters"} |
- Update user details at signup phase 2
path | api/v1/core/update-user/<address> |
Type | PUT |
Description | To update user details from the DB |
Header | Jwt token |
No | Param name | type | Description | Required |
1` | address | String | Solana address of the user | True |
No | Param name | type | Description | Required |
1 | about | String | Bio for user | True |
2 | name | String | Name of user | True |
3 | pfp | String | Url for user image | True |
4 | content_tags | List of strings | Tags which represents the content | False |
5 | identity_tags | List of strings | Tags which represents the user | False |
6 | Profile_metadata | Json | Metadata of user | False |
1. | Update user details | {
about: “Exploring the world of Solana and building cool projects” pfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg” content_tags: [ “solana”, “nft” ] identity_tags: [“developer”, “SDE”] Profile_metadata: {} } |
No | Status Code | Response |
1. | 200 | {
address: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”, name: “Mark Status”, verified: false last_cards_marked: 1703721486 about: “Exploring the world of Solana and building cool projects” pfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg” content_tags: [ “solana”, “nft” ] last_attested: 1703721486 identity_tags: [“developer”, “SDE”] Badges: [“bonk] Profile_metadata: {} } |
2. | 400 | {"error": "Missing required parameters"} |
- Get user published card details
path | api/v1/core/cards/published/<address> |
Type | GET |
Description | To fetch published card from the DB |
Header | Jwt token |
No | Param name | type | Description | Required |
1` | address | String | Solana address of the user | True |
No | Status Code | Response |
1. | 200 [List of json cards] | [{
date: “11 Feb 2024”, cardType: “DataCard”, category: “Information Technology”, content: “Visits to huggingface.co increased by” metadata: { contentImageUrl: “”, contentData: “30%” likeCount: 15, shareCount: 20, digCount: 15 } }] |
2. | 400 | {"error": "Missing required parameters"} |
- Delete published card details for any user
path | api/v1/core/cards/published/<address> |
Type | DELETE |
Description | To delete published card from the DB for any user before card is not attested |
Header | Jwt token |
No | Param name | type | Description | Required |
1` | address | String | Solana address of the user | True |
No | Param name | type | Description | Required |
1` | ids | List of strings | List of ids for published cards | True |
No | Status Code | Response |
1. | 200 | {"message": "<count of deleted cards> published cards deleted from db for <user_address>"} |
2. | 400 | {"error": "Missing required parameters"} |
- Get user pending card details
path | api/v1/core/cards/pending/<address> |
Type | GET |
Description | To fetch pending card from the DB |
Header | Jwt token |
No | Param name | type | Description | Required |
1` | address | String | Solana address of the user | True |
No | Status Code | Response |
1. | 200 [List of json cards] | [{
date: “11 Feb 2024”, userName: “Den Brown”, userPfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg” content: “Visits to huggingface.co increased by” links: { domain: 'www.huggingface.co', title: 'Hugging Face – The AI community building the future.' } }] |
2. | 400 | {"error": "Missing required parameters"} |
- Delete pending card details for any user
path | api/v1/core/cards/pending/<address> |
Type | DELETE |
Description | To delete removed pending card from the DB for any user |
Header | Jwt token |
No | Param name | type | Description | Required |
1` | address | String | Solana address of the user | True |
No | Param name | type | Description | Required |
1` | ids | List of strings | List of ids for pending cards | True |
No | Status Code | Response |
1. | 200 | {"message": "<count of deleted cards> pending cards deleted from db for <user_address>"} |
2. | 400 | {"error": "Missing required parameters"} |
- Get all cards and user details of any user
path | api/v1/core/user/<address>/published-cards/info |
Type | GET |
Description | To all published card and user from the DB |
Header | Jwt token |
No | Param name | type | Description | Required |
1` | address | String | Solana address of the user | True |
No | Status Code | Response |
1. | 200 | {
"published_cards": [ { "cardType": "DataCard", "category": "", "content": "Visits to huggingface.co increased by", "date": "18 Mar 2024", "metadata": { "contentData": "30%", "contentImageUrl": "", "digCount": 15, "likeCount": 15, "shareCount": 20 } }, { "cardType": "ImageCard", "category": "", "content": "New ML model architecture released", "date": "19 Mar 2024", "metadata": { "contentData": "", "contentImageUrl": "https://example.com/image1.jpg", "digCount": 20, "likeCount": 25, "shareCount": 30 } }, { "cardType": "DomainVisitCard", "category": "", "content": "Visits to openai.com", "date": "20 Mar 2024", "metadata": { "contentData": "50,000 visits", "contentImageUrl": "", "digCount": 10, "likeCount": 10, "shareCount": 15 } } ], "user": { "about": "developer with 1 YOE in java", "address": "7B3FeQJ2SZa4Tw9gJXu7zzdmivY9ot17uXSCko1zMefh", "badges": [ "bonk", "bonk_v2" ], "content_tags": [ "java", "springBoot" ], "identity_tags": [ "developer", "backend" ], "last_attested": 1710738880, "last_cards_marked": 1710738880, "name": "den marchov", "profile_metadata": { "alt_image_tag": "7B3FeQJ2SZa4Tw9gJXu7zzdmivY9ot17uXSCko1zMefd" }, "verified": false } } |
2. | 400 | {"error": "Missing required parameters"} |
3 | 404 | If we do not pass users in |
This program is free software under MIT license. Please see the LICENSE file in our repository for the full text.