Skip to content

pinyuho/fds-be

 
 

Repository files navigation

fds-be: Async Web Backend for RDOGS-Friendz

A python=3.9-asyncio-based web backend, using web framework fastapi.

Note

Setup database

There two ways to setup your database.

1. Connect to our database

  • You only have to ask developer to get .env file.

2. Build your own database on localhost

  1. First, import schemas.sql to postgresql server

    psql -U your_user_name -d new_db_name -f schemas.sql
    
  2. Second, on your postgresql cmd:

    # please remember to replace your path
    \COPY location(name) FROM '/path/fds-be/data_collection/location.csv' DELIMITER ',' CSV HEADER;
    \COPY category(name) FROM '/path/fds-be/data_collection/category.csv' DELIMITER ',' CSV HEADER;
    \COPY department(school, department_name) FROM '/path/fds-be/data_collection/department.csv' DELIMITER ',' CSV HEADER;
    

    or in your postgresql cmd:

    \i import_data.sql
    
  3. Finally, revise .env file to connect to your local database.

    PG_HOST=postgresql://localhost
    PG_PORT=5432
    PG_USERNAME=your_username
    PG_PASSWORD=your_password
    PG_DBNAME=your_dbname
    PG_DBURL= postgresql://your_username:your_password@localhost/your_dbname
    

Setup test server

0. python virtual environment

(name whatever you like)

conda create --name fds-async python=3.9
conda activate fds-async

or

python3 -m venv fds-async
./fds-async/Scripts/activate

or create a virtual environment using pipenv (faster and lighter)

pip install pipenv
pipenv shell

1. Environment

pip install -r requirements.txt
copy .env.example .env

Or on Unix-based system, run

pip install -r requirements.txt
cp .env.example .env

Then fill out the environment variables in .env

2. Start the server

pip install uvicorn
uvicorn main:app

On your terminal you should see:

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process xxxx using watchgod
INFO:     Started server process xxxx
INFO:     Waiting for application startup.
INFO:     Application startup complete.

Now you can go to http://127.0.0.1:8000 and test it.
You may also turn up the auto-reload option, or change the host & port with --host and --port:

uvicorn main:app --reload --host 0.0.0.0 --port 80

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 87.7%
  • PLpgSQL 8.0%
  • Jupyter Notebook 3.8%
  • Other 0.5%