Metadata-Version: 2.3
Name: yak-server
Version: 0.45.0
Summary: Football bet rest/graphql server
Project-URL: Homepage, https://github.com/yak-toto/yak-server
Project-URL: Repository, https://github.com/yak-toto/yak-server
Author-email: Guillaume Le Pape <gui.lepape25@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api,graphql,mysql,rest
Classifier: Environment :: Web Environment
Classifier: Framework :: FastAPI
Classifier: Framework :: Pydantic
Classifier: Framework :: Pydantic :: 2
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Classifier: Topic :: Database :: Database Engines/Servers
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Requires-Python: >=3.8
Requires-Dist: argon2-cffi==23.1.0
Requires-Dist: fastapi==0.115.0
Requires-Dist: pendulum==3.0.0
Requires-Dist: pydantic-settings==2.5.2
Requires-Dist: pyjwt==2.9.0
Requires-Dist: pymysql[rsa]==1.1.1
Requires-Dist: sqlalchemy-utils==0.41.2
Requires-Dist: sqlalchemy==2.0.35
Requires-Dist: strawberry-graphql==0.242.0
Requires-Dist: typer==0.12.5
Provides-Extra: db-migration
Requires-Dist: alembic==1.13.2; extra == 'db-migration'
Provides-Extra: profiling
Requires-Dist: yappi==1.6.0; extra == 'profiling'
Provides-Extra: sync
Requires-Dist: beautifulsoup4[lxml]==4.12.3; extra == 'sync'
Requires-Dist: httpx==0.27.2; extra == 'sync'
Description-Content-Type: text/markdown

# Yak-toto

[![PyPI](https://img.shields.io/pypi/v/yak-server?label=stable)](https://pypi.org/project/yak-server/)
[![Python Versions](https://img.shields.io/pypi/pyversions/yak-server)](https://pypi.org/project/yak-server/)
[![codecov](https://codecov.io/gh/yak-toto/yak-server/branch/main/graph/badge.svg?token=EZZK5SY5BL)](https://codecov.io/gh/yak-toto/yak-server)
[![🔐 CodeQL](https://github.com/yak-toto/yak-server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/yak-toto/yak-server/actions/workflows/codeql-analysis.yml)
[![Testing](https://github.com/yak-toto/yak-server/actions/workflows/test.yml/badge.svg)](https://github.com/yak-toto/yak-server/actions/workflows/test.yml)

## Requisites

- Ubuntu 22.04
- MySQL 8.0.30

## How to build the project

### Database

Install and start mysql server on port 3306. Add a database named `yak_toto`. In root folder, create a dotenv file named `.env` and fill your MySQL user name, password and database. When backend start, this configuration is automatically loaded.

```text
MYSQL_USER_NAME=my_user_name
MYSQL_PASSWORD=my_password
MYSQL_DB=my_database_name
```

You can also set MySQL port by adding `MYSQL_PORT=my_port` to `.env` file. If not set, it will be 3306 by default.

### Backend

Run your project in a Python env is highly recommend. You can use venv python module using the following command:

```bash
uv venv
. .venv/bin/activate
```

Fetch all packages using pip with the following command:

```bash
uv pip install -r requirements.txt
```

Before starting the backend, add `JWT_SECRET_KEY` and `JWT_EXPIRATION_TIME` in `.env` same as the MySQL user name and password. As
login system is using JSON Web Token, a secret key is required and an expiration time (in seconds). To generate one, you can use the python built-in `secrets` module.

```py
>>> import secrets
>>> secrets.token_hex(16)
'9292f79e10ed7ed03ffad66d196217c4'
```

```text
JWT_SECRET_KEY=9292f79e10ed7ed03ffad66d196217c4
JWT_EXPIRATION_TIME=1800
```

Also, automatic backup can be done through `yak_server/cli/backup_database` script. It can be run using `yak db backup`.

Finally, fastapi needs some configuration to start. Last thing, for development environment, debug needs to be activated with a additional environment variable:

```text
DEBUG=1
```

And then start backend with:

```bash
uvicorn --reload yak_server:create_app --factory
```

### Data initialization

To run local testing, you can use the script `create_database.py`, `initialize_database.py` and `create_admin.py` located in `yak_server/cli` folder. To select, set `COMPETITION` environment variable in `.env`. It will read data from `yak_server/data/{COMPETITION}/`.

### Testing

To set up test, please add a MySQL database named `yak_toto_test`. It will contain all the records created during unit tests. This database is cleaned everytime you run test. That's why a different database is created to avoid deleting records you use for your local testing.

Yak-server is using `pytest` to run tests.

## Profiling

You can profile by adding this line in the `.env`

```text
PROFILING=1
```

Be careful, you need to be in debug mode to activate the profiling. In production mode, adding the environment variable will have no impacts.
