Giter Site home page Giter Site logo

mbcaldeiro / pyms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from python-microservices/pyms

0.0 0.0 0.0 669 KB

Library of utils to create REST Python Microservices

Home Page: https://py-ms.readthedocs.io/en/latest/

License: GNU General Public License v3.0

Python 100.00%

pyms's Introduction

Python Microservices Library

PyPI version Build Status Coverage Status Requirements Status Total alerts Language grade: Python Documentation Status Gitter

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.

Get started with Installation and then get an overview with the Quickstart.

Documentation

To know how to use, install or build a project see the docs.

Motivation

When we started creating a microservice with no idea, we were looking for tutorials, guides, best practices, but we found nothing to create professional projects. Most articles say:

  • "Install flask"
  • "Create routes"
  • (Sometimes) "Create a swagger specs"
  • "TA-DA! you have a microservice"

But... what happens with our configuration out of code like Kubernetes configmap? what happens with transactionality? If we have many microservices, what happens with traces?.

There are many problems around Python and microservices and we can't find anyone to give a solution.

We start creating these projects to try to solve all the problems we have found in our professional lives about microservices architecture.

Nowadays, is not perfect and we have a looong roadmap, but we hope this library could help other fellas and friends ;)

Installation

pip install py-ms[all]

Quickstart

You need to create 2 files: main.py and config.yml:

  • main.py
from flask import jsonify

from pyms.flask.app import Microservice

ms = Microservice() # 1.1
app = ms.create_app() # 2.1


@app.route("/") # 3.1
def example():
    return jsonify({"main": "hello world"})


if __name__ == '__main__':
    app.run()
  • config.yml
pyms:
  services: # 1.2
    requests:
      data: {}
  config: # 1.3
    DEBUG: true
    APP_NAME: business-glossary
    APPLICATION_ROOT : ""
    SECRET_KEY: "gjr39dkjn344_!67#"

So what did that code do?

  1. Create a instance of PyMS Microservice class (#1.1). This initialization injects the configuration defined in the 1.3 block and could be accessed through current_app.config like typical Flask config. Then, initialize the service defined in the 1.2 block. See Services for more details.

  2. Initialize a Flask instance, Connexion if it was defined in the pyms configuration block, create a tracer, add health-check blueprint, initialize libs and set the PyMS Microservice in ms attribute and you can access to it with current_app.ms. This steps has their each functions and you can easy override it.

  3. create_app returns the flask instance which you can interact with as a typical flask app

See Documentation to learn more.

Create a project from scaffold

PyMS has a command line option to create a project template like Microservices Scaffold. This command uses cookiecutter to download and install this template

[Warning] You must run first pip install cookiecutter==1.7.0

pyms startproject

this output a lot of options step by step:

project_repo_url [https://github.com/python-microservices/microservices-scaffold]:
project_name [Python Microservices Boilerplate]: example project
project_folder [example_project]:
project_short_description [Python Boilerplate contains all the boilerplate you need to create a Python package.]:
create_model_class [y]:
microservice_with_swagger_and_connexion [y]:
microservice_with_traces [y]:
microservice_with_metrics [y]:
application_root [/example_project]:
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]:

When you finish introducing the options, a project will be created in [project_folder] folder

How To contribute

We appreciate opening issues and pull requests to make PyMS even more stable & useful! See This doc for more details.

pyms's People

Contributors

avara1986 avatar pyup-bot avatar alexppg avatar javierluna avatar devendra-nh avatar fabianfalon avatar f-arruza avatar ooigavin avatar hcamino avatar ibledy avatar liangjq avatar kingdarboja avatar miguelgrubin avatar lcd1232 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.