Skip to content

ytsai-a10/pyms2

Repository files navigation

microservices-scaffold

Python Microservice Scaffold is an example of how to structure a Flask Microservice Project. This Scaffold is build over PyMS package. PyMS is a Microservice chassis pattern like Spring Boot (Java) or Gizmo (Golang). PyMS is a collection of libraries, best practices and recommended ways to build microservices with Python which handles cross-cutting concerns:

  • Externalized configuration
  • Logging
  • Health checks
  • Metrics
  • Distributed tracing

Build Status Coverage Status Requirements Status Updates Python 3

How to run the scaffold

Installation

Install with virtualenv

virtualenv --python=python[3.6|3.7|3.8] venv
source venv/bin/activate
pip install -r requirements.txt

Install with pipenv

pip install pipenv
pipenv install

Advantages over plain pip and requirements.txt

Pipenv generates two files: a Pipfileand a Pipfile.lock.

  • Pipfile: Is a high level declaration of the dependencies of your project. It can contain "dev" dependencies (usually test related stuff) and "standard" dependencies which are the ones you'll need for your project to function
  • Pipfile.lock: Is the "list" of all the dependencies your Pipfile has installed, along with their version and their hashes. This prevents two things: Conflicts between dependencies and installing a malicious module.

For a more in-depth explanation please refer to the official documentation.

Run your python script

python3 manage.py runserver

Check the result

Your default endpoints will be in this url:

http://127.0.0.1:5000/[APPLICATION_ROOT]/

This URL is set in your config.yml:

pyms:
  config:
    DEBUG: false
    TESTING: false
    APP_NAME: Template
    APPLICATION_ROOT : "" # <!---

You can acceded to a swagger ui in the next url:

http://127.0.0.1:5000/[APPLICATION_ROOT]/ui/

This PATH is set in your config.yml:

pyms:
  services:
    swagger:
      path: "swagger"
      file: "swagger.yaml"
      url: "/ui/" # <!---

Read more info in the documentation page: https://microservices-scaffold.readthedocs.io/en/latest/

Docker

You can dockerize this microservice with these steps:

  • Create and push the image

    docker build -t films -f Dockerfile .

  • Run the image:

    docker run -d -p 5000:5000 films

About

Python Microservice Test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published