Skip to content

benrucker/whid-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

whid API

Maintainability Test Coverage action Known Vulnerabilities

This project is a secret API.

Usage

  1. Install Python 3.10 or higher
  2. Install pip if you don't have it
  3. Open a terminal and clone this repo
git clone https://github.com/benrucker/whid-api
  1. cd into the repo
cd whid-api
  1. Create and activate a virtual environment
# Windows:
python -m pip install venv
python -m venv .venv
.\\.venv\\Scripts\\activate
# Mac and Linux:
python3 -m pip install venv
python3 -m venv .venv
. .venv/bin/activate
  1. Install the requirements
python -m pip install -r requirements.txt
  1. Create a file named .env in the root directory of the repo
  2. Add in values for DB_URL and API_TOKENS. For example:
DB_URL="sqlite:///./sql_app.db"
API_TOKENS=["hello"]
  1. Run the app
# dev
uvicorn api.main:app --reload
# production
./run
  1. View the documentation at http://127.0.0.1:8000/docs

Using alembic

When a change has been made to the DB schema, you need to use alembic to update the production database. To do this:

  1. cd to the project folder
  2. git pull or run ./update
  3. Generate a new almebic checkpoint: alembic revision --autogenerate -m "<What was changed>"
  4. Update the db: alembic upgrade head
    • If you get an error with null values, update the revision script like this:
    # old:
    op.add_column('channel', sa.Column('type', sa.String(), nullable=True))
    # fixed:
    op.add_column('channel', sa.Column('type', sa.String()))
    op.execute('update channel set type = \'text\'')
    op.alter_column('channel', 'type', nullable=False)
    • Rerun the update command
  5. If not done already, HUP the running process with ./update

Languages