Skip to content

hisdream86/python-sanic-example

Repository files navigation

python-sanic-example

Example Web API application using Python Sanic

How to run

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

$ 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
# 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

You can find initial version of migration file at alembic/versions/0000_init_products.py

$ 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

About

Simple web application example using the python sanic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages