Create the Python Microservice with `pyms`

Python Microservices — PyMS

PyMS, Python MicroService, 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

PyMS is powered by Flask, Connexion and Opentracing.

Activate the Virtual Environment

These steps are according to my skill level in python for creating a virtual environment

python3 -m venv pyms-tutorial
source pyms-tutorial/bin/activate

Environment activation is not mandatory to create the microservice with `pyms`

Install pyms

pip install py-ms[all]

Create a project from scaffold

PyMS has a command-line option to create a project template like Microservices Scaffold.


- `PyMS` uses cookiecutter to download and install this template

pip install cookiecutter

- Create a git repository and keep the repo URL copied [Optional]

Create the Project

pyms startproject

Interactive way of answering a few questions to create the project.

pyms startprojectYou've downloaded /home/balu/.cookiecutters/cookiecutter-pyms before. Is it okay to delete and re-download it? [yes]: yes1. project_repo_url []:    2. project_name [Python Microservices Boilerplate]: Python Microservice3. project_folder [python_microservice]: 4. project_short_description [Python Boilerplate contains all the boilerplate you need to create a Python package.]: Python Microservice Sample with PyMS5. create_model_class [y]: y6. microservice_with_swagger_and_connexion [y]: y7. microservice_with_traces [y]: y8. microservice_with_metrics [y]: y9. application_root [/python_microservice]:  /python_microservice10. Select open_source_license:
1 - MIT license
2 - BSD license
3 - ISC license
4 - Apache Software License 2.0
5 - GNU General Public License v3
6 - Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 6

Run Application

cd python_microservice/
pip install -r requirements.txt

Do some code changes in the which in bold or check with the tutorials in Tutorial Example.

from flask_script import Manager
from flask import jsonify, current_app, request
from import create_app
app = create_app()
manager = Manager(app)
def index():"There are my headers: \n{}".format(request.headers))
return jsonify({"main": "hello world {}".format(current_app.config["APP_NAME"])})
if __name__ == '__main__'

run the application with

python runserver


INFO:werkzeug: * Running on (Press CTRL+C to quit)

Run the application as a container

Create the docker images with

docker build -t pyms-tutorial -f Dockerfile .

Run the container with

docker run -d -p 5001:5000 pyms-tutorial

Now the application is up and running on ``


1. [PyMS](

2. [Python Microservices Github](



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store