Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hisdream86/python-sanic-example
https://github.com/hisdream86/python-sanic-example
Last synced: about 14 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/hisdream86/python-sanic-example
- Owner: hisdream86
- License: mit
- Created: 2021-12-05T02:07:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-29T07:51:59.000Z (almost 3 years ago)
- Last Synced: 2023-03-21T20:27:06.983Z (over 1 year ago)
- Language: Python
- Size: 139 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# python-sanic-example
Example Web API application using [Python Sanic](https://github.com/sanic-org/sanic)## How to run
### 1. [Install poetry](https://python-poetry.org/docs/)
```sh
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
poetry config virtualenvs.in-project true
```### 2. Create a virtual environment and install dependencies
```sh
$ poetry update
```### 3. Set environment variables
Set environment variables for integrating your database- `PG_HOST`: Postgres hostname
- `PG_PORT`: Postgres port
- `PG_DATABASE`: Posrgres database name
- `PG_USER`: Postgres username
- `PG_PASSWORD`: Postgres password```sh
# Example$ export PG_HOST='localhost'
$ export PG_PORT='5432'
$ export PG_DATABASE='sanic_example'
$ export PG_USER='sanic_example'
$ export PG_PASSWORD='sanic_example'
```### 4. Initialize your database
Create `product` table using [alembic](https://alembic.sqlalchemy.org/en/latest/)> You can find initial version of migration file at `alembic/versions/0000_init_products.py`
```sh
$ alembic upgrade head
```### 5. Run application
You can run application with simple command below
```
$ source .venv/bin/activate
$ python main.py
```Or you can run application with docker
```
$ docker build -t python-sanic-example:test .
$ docker run -it -p 8080:8080 python-sanic-example:test
```