You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-14Lines changed: 39 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,26 +39,51 @@ Nowadays, is not perfect and we have a looong roadmap, but we hope this library
39
39
pip install py-ms
40
40
```
41
41
42
-
## Structure
42
+
#Quickstart
43
43
44
-
### pyms/config
45
-
Module to read yaml or json configuration from a dictionary or a path.
44
+
You need to create 2 files: main.py and config.yml:
46
45
47
-
### pyms/flask/app
48
-
With the function `create_app` initialize the Flask app, register [blueprints](http://flask.pocoo.org/docs/0.12/blueprints/)
49
-
and initialize all libraries such as Swagger, database, trace system, custom logger format, etc.
46
+
main.py
47
+
```python
48
+
from flask import jsonify
50
49
51
-
### pyms/flask/services
52
-
Integrations and wrappers over common libs like request, swagger, connexion
50
+
from pyms.flask.app import Microservice
53
51
54
-
### pyms/flask/healthcheck
55
-
This view is usually used by Kubernetes, Eureka and other systems to check if our application is running.
52
+
ms = Microservice(path=__file__) # 1.1
53
+
app = ms.create_app() # 2.1
56
54
57
-
### pyms/logger
58
-
Print logger in JSON format to send to server like Elasticsearch. Inject span traces in logger.
59
55
60
-
### pyms/tracer
61
-
Create an injector `flask_opentracing.FlaskTracer` to use in our projects.
56
+
@app.route("/") # 3.1
57
+
defexample():
58
+
return jsonify({"main": "hello world"})
59
+
60
+
61
+
if__name__=='__main__':
62
+
app.run()
63
+
```
64
+
65
+
config.yml
66
+
```yaml
67
+
pyms: # 1.2
68
+
requests:
69
+
data: {}
70
+
ms: # 1.3
71
+
DEBUG: true
72
+
APP_NAME: business-glossary
73
+
APPLICATION_ROOT : ""
74
+
SECRET_KEY: "gjr39dkjn344_!67#"
75
+
```
76
+
77
+
### So what did that code do?
78
+
79
+
1. Create a instance of PyMS Microservice class (#1.1). This initialization inject the configuration defined in the
80
+
1.3 block and could be accessed through current_app.config. Then, initialize the service defined in the 1.2 block. See [Services](services.md) for more details.
Copy file name to clipboardExpand all lines: docs/configuration.md
+43-2Lines changed: 43 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,12 @@
1
1
# Configuration
2
2
3
+
## Environments variables of PyMS:
4
+
5
+
**CONFIGMAP_FILE**: The path to the configuration file. By default, PyMS search the configuration file in your
6
+
actual folder with the name "config.yml"
7
+
**CONFIGMAP_SERVICE**: the name of the keyword that define the block of key-value of [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/)
8
+
and your own configuration (see the next section to more info)
9
+
3
10
## Create configuration
4
11
Each microservice needs a config file in yaml or json format to work with it. This configuration contains
5
12
the Flask settings of your project and the [Services](services.md). With this way to create configuration files, we
@@ -44,7 +51,6 @@ or in a config.json:
44
51
45
52
This file could contains this keywords:
46
53
47
-
48
54
## pyms block
49
55
50
56
```pyms```: all subsets inside this keyword are the settings of this library. Each keyword will be a service of our
@@ -96,6 +102,8 @@ ms1-api:
96
102
TESTING: false
97
103
```
98
104
105
+
You can set this keyword with the environment var **CONFIGMAP_SERVICE**.
106
+
99
107
## Import Configuration
100
108
With pyms, all configuration is stored as flask configuration and it can be acceded from:
101
109
@@ -142,4 +150,37 @@ API = Api(
142
150
```
143
151
144
152
**IMPORTANT:** If you use this method to get configuration out of context, you must set the `CONFIGMAP_SERVICE` or set
145
-
the default key `ms` for your configuration block in your config.yml
153
+
the default key `ms` for your configuration block in your config.yml
154
+
155
+
156
+
## Looking for Configuration file with Kubernetes Configmaps
157
+
By default, Microservice class search a config.yml in the same path. You can set a different route or set a json file.
158
+
To change this path, define a environment variable `CONFIGMAP_FILE`.
159
+
160
+
This way of looking for the configuration is useful when you work with Docker and Kubernetes. For example, you can integrate
161
+
a configmap of Kubernetes, with this microservice and a deployment with:
Copy file name to clipboardExpand all lines: docs/index.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,17 @@
1
1
# Welcome to PyMS
2
2
3
-
PyMS, Python MicroService, is a collection of libraries, best practices and recommended ways to build
4
-
microservices with Python.
3
+
PyMS, Python MicroService, is a [Microservice chassis pattern](https://microservices.io/patterns/microservice-chassis.html)
4
+
like Spring Boot (Java) or Gizmo (Golang). PyMS is a collection of libraries, best practices and recommended ways to build
5
+
microservices with Python which handles cross-cutting concerns:
6
+
- Externalized configuration
7
+
- Logging
8
+
- Health checks
9
+
- Metrics (TODO)
10
+
- Distributed tracing
11
+
12
+
PyMS is powered by [Flask](https://flask.palletsprojects.com/en/1.1.x/), [Connexion](https://github.com/zalando/connexion) and [Opentracing](https://opentracing.io/).
13
+
14
+
Get started with [Installation](installation.md) and then get an overview with the [Quickstart](quickstart.md).
5
15
6
16
## Motivation
7
17
@@ -24,9 +34,11 @@ Nowadays, is not perfect and we have a looong roadmap, but we hope this library
24
34
25
35
26
36
## Index:
27
-
*[PyMS structure](structure.md)
37
+
*[Installation](installation.md)
38
+
*[Quickstart](quickstart.md)
28
39
*[Configuration](configuration.md)
29
40
*[Services](services.md)
41
+
*[PyMS structure](structure.md)
30
42
*[Microservice class](ms_class.md)
31
43
*[Quick start and examples](examples.md)
32
44
*[Structure of a microservice project](structure_project.md)
This page gives a good introduction to PyMS. It assumes you already have PyMS installed. If you do not, head over to the [Installation](installation.md) section.
4
+
5
+
You need to create 2 files: main.py and config.yml:
6
+
7
+
main.py
8
+
```python
9
+
from flask import jsonify
10
+
11
+
from pyms.flask.app import Microservice
12
+
13
+
ms = Microservice(path=__file__) # 1.1
14
+
app = ms.create_app() # 2.1
15
+
16
+
17
+
@app.route("/") # 3.1
18
+
defexample():
19
+
return jsonify({"main": "hello world"})
20
+
21
+
22
+
if__name__=='__main__':
23
+
app.run()
24
+
```
25
+
26
+
config.yml
27
+
```yaml
28
+
pyms: # 1.2
29
+
requests:
30
+
data: {}
31
+
ms: # 1.3
32
+
DEBUG: true
33
+
APP_NAME: business-glossary
34
+
APPLICATION_ROOT : ""
35
+
SECRET_KEY: "gjr39dkjn344_!67#"
36
+
```
37
+
38
+
## So what did that code do?
39
+
40
+
1. Create a instance of PyMS Microservice class (#1.1). This initialization inject the configuration defined in the
41
+
1.3 block and could be accessed through current_app.config. Then, initialize the service defined in the 1.2 block. See [Services](services.md) for more details.
0 commit comments