https://github.com/unmade/hangman
Simple REST version of hangman
https://github.com/unmade/hangman
fastapi python3 sqlalchemy
Last synced: 6 months ago
JSON representation
Simple REST version of hangman
- Host: GitHub
- URL: https://github.com/unmade/hangman
- Owner: unmade
- Created: 2020-02-07T20:17:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-26T17:39:02.000Z (almost 5 years ago)
- Last Synced: 2025-02-14T23:34:18.374Z (11 months ago)
- Topics: fastapi, python3, sqlalchemy
- Language: Python
- Homepage: http://apihangman.herokuapp.com/docs
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hangman
This is simple REST API to play Hangman game
[](https://github.com/unmade/hangman/blob/master/.github/workflows/lint-and-test.yml)
[](https://github.com/unmade/hangman/blob/master/.github/workflows/deploy.yml)
[](https://codecov.io/gh/unmade/hangman)
## Configuration
App can be configured with environment variables
### App
|Name | Required | Default | Description|
|:--------|:-------- |:------- |:-----------|
|APP_NAME | - | Hangman | Specifies app name |
|APP_VERSION | - | - | Specifies app version. This env is set during build |
|APP_DEBUG | - | False | Whether to run app in debug mode |
### Databases
|Name | Required | Default | Description|
|:--------|:-------- |:------- |:-----------|
|DATABASES_DSN | + | - | Database DSN. Examples: `sqlite:///./test.db`, `postgresql://user:password@host:port/name` |
### Game
|Name | Required | Default | Description|
|:--------|:-------- |:------- |:-----------|
|HANGMAN_WORDS | - | "3dhubs,marvin,print,filament,order,layer" | String of comma-separated words to use in the game |
|HANGMAN_LIVES | - | 5 | Specifies how much times user can ask letters that don't exist |
### Sentry
|Name | Required | Default | Description|
|:--------|:-------- |:------- |:-----------|
|SENTRY_DSN | - | - | Sentry DSN |
## Documentation
Check out interactive documentation [here](https://apihangman.herokuapp.com/docs)
## Development
### Running locally
Create a new virtual environment:
```bash
python3 -m venv .venv
source ./.venv/bin/activate
```
Install requirements:
```bash
pip install -r requirements/base.txt -r requirements/test.txt
```
Install pre-commit hooks:
```bash
pre-commit install
```
Set python path and the path to db:
```bash
export PYTHONPATH="$(pwd)"
export DATABASE_DSN=sqlite:///./test.db
```
Apply migrations:
```bash
alembic upgrade head
```
Run the app:
```bash
uvicorn app.main:app --reload
```
### Testing
To run test just type:
```bash
DATABASE_DSN=sqlite:// pytest --cov
```
### Running in Docker
Running app docker is pretty straightforward:
```bash
docker build . -t "${IMAGE_NAME}"
docker run --rm --env DATABASE_DSN="${DATABASE_DSN}" -p 8000:80 "${IMAGE_NAME}"
```
### Adding new requirements
This project relies on [pip-tools](https://github.com/jazzband/pip-tools) to manage requirements.
To add a new one update one of the *.in files in [requirements](requirements) directory,
and then run:
```bash
pip-compile requirements/{updated_file}.in
```
To sync with your env:
```bash
pip-sync requirements/base.txt requirements/test.txt requirements/prod.txt
```