8000 Updated documentation (#99) · python-microservices/pyms@8cb721e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8cb721e

Browse files
avara1986alexppg
andauthored
Updated documentation (#99)
* Fix connexion issue #1135 pypa/pipenv#4147 * Added more tests to swagger * Updated docstrings * Fix condition * Revert "Fix condition" Co-authored-by: Àlex Pérez <alexperezpujol@disroot.org>
1 parent 13412d4 commit 8cb721e

File tree

13 files changed

+367
-94
lines changed

13 files changed

+367
-94
lines changed

docs/examples.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Examples
22

3+
## Example 1: Basic Example
4+
35
```bash
46
pip install py-ms[all]
57
```
@@ -19,7 +21,7 @@ from flask import jsonify, current_app
1921

2022
from pyms.flask.app import Microservice
2123

22-
ms = Microservice(path=__file__)
24+
ms = Microservice()
2325
app = ms.create_app()
2426

2527

@@ -38,4 +40,110 @@ python main.py
3840

3941
Open in your browser http://localhost:5000/
4042

43+
## Example 2: Create your Microservice class
44+
45+
Create a class that inherit from `pyms.flask.app.Microservice` and override methods with your own configuration.
46+
The next example show how to innit a lib like [Flask Babel](https://pythonhosted.org/Flask-Babel/)
47+
48+
main.py:
49+
50+
```python
51+
from flask_babel import Babel
52+
from pyms.flask.app import Microservice
53+
54+
class MyMicroservice(Microservice):
55+
def init_libs(self):
56+
babel = Babel(self.application)
57+
58+
return self.application
59+
60+
ms = MyMicroservice()
61+
app = ms.create_app()
62+
```
63+
64+
## Example 2: Initialize SQLAlchemy
65+
66+
The next example show how to innit a lib like [Flask SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/)
67+
68+
config.yml:
69+
70+
```yaml
71+
pyms:
72+
config:
73+
DEBUG: true
74+
APP_NAME: MyDB
75+
APPLICATION_ROOT: ""
76+
SQLALCHEMY_DATABASE_URI: mysql+mysqlconnector://user:pass@0.0.0.0/myschema
77+
```
78+
main.py:
79+
80+
```python
81+
from flask_sqlalchemy import SQLAlchemy
82+
from pyms.flask.app import Microservice
83+
84+
DB = SQLAlchemy()
85+
86+
87+
class MyMicroservice(Microservice):
88+
def init_libs(self):
89+
self.application.config["SQLALCHEMY_ENGINE_OPTIONS"] = {
90+
'pool_size': 10,
91+
'pool_recycle': 120,
92+
'pool_pre_ping': True
93+
}
94+
DB.init_app(self.application)
95+
96+
ms = MyMicroservice()
97+
app = ms.create_app()
98+
```
99+
100+
## Example 3: Create your logger
101+
102+
The next example show how to create a personal logger for your application
103+
104+
```python
105+
import logging.config
106+
107+
from pyms.flask.app import Microservice
108+
109+
110+
class MyMicroservice(Microservice):
111+
def init_logger(self):
112+
level = "INFO"
113+
LOGGING = {
114+
'version': 1,
115+
'disable_existing_loggers': False,
116+
'formatters': {
117+
'console': {
118+
'format': '[%(asctime)s][%(levelname)s] %(name)s '
119+
'%(filename)s:%(funcName)s:%(lineno)d | %(message)s',
120+
'datefmt': '%H:%M:%S',
121+
},
122+
},
123+
'handlers': {
124+
'console': {
125+
'level': level,
126+
'class': 'logging.StreamHandler',
127+
'formatter': 'console'
128+
},
129+
},
130+
'loggers': {
131+
'': {
132+
'handlers': ['console'],
133+
'level': level,
134+
'propagate': True,
135+
},
136+
'root': {
137+
'handlers': ['console'],
138+
'level': level,
139+
'propagate': True,
140+
},
141+
}
142+
}
143+
logging.config.dictConfig(LOGGING)
144+
145+
ms = MyMicroservice(path=__file__)
146+
app = ms.create_app()
147+
```
148+
41149
See [this Github page](https://github.com/python-microservices/pyms/tree/master/examples) to see a examples

docs/imgs/PyMSdistributedtracing.png

49.4 KB
Loading

docs/imgs/multiple-ms.png

143 KB
Loading

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ Nowadays, is not perfect and we have a looong roadmap, but we hope this library
4646
* [Encrypt/Decrypt Configuration](encrypt_decryt_configuration.md)
4747
* [Command line](command_line.md)
4848
* [Examples](examples.md)
49+
* [Tutorials](tutorials.md)
50+
* [Tutorial: Propagate traces](tutorial_propagate_traces.md)
4951
* [PyMS structure](structure.md)
5052
* [Structure of a microservice project](structure_project.md)

docs/ms_class.md

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -96,97 +96,5 @@ Microservice class initialize the libraries and other process by this way:
9696
return self.application
9797
```
9898

99-
## Example 1: Basic Example
100-
101-
Create a class that inherit from `pyms.flask.app.Microservice` and override methods with your own configuration.
102-
The next example show how to innit a lib like [Flask Babel](https://pythonhosted.org/Flask-Babel/)
103-
104-
```python
105-
from flask_babel import Babel
106-
from pyms.flask.app import Microservice
107-
108-
class MyMicroservice(Microservice):
109-
def init_libs(self):
110-
babel = Babel(self.application)
111-
112-
return self.application
113-
114-
ms = MyMicroservice(path=__file__)
115-
app = ms.create_app()
116-
```
117-
118-
## Example 2: Initialize SQLAlchemy
119-
120-
The next example show how to innit a lib like [Flask SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/)
121-
122-
```python
123-
from flask_sqlalchemy import SQLAlchemy
124-
from pyms.flask.app import Microservice
125-
126-
DB = SQLAlchemy()
127-
128-
129-
class MyMicroservice(Microservice):
130-
def init_libs(self):
131-
self.application.config["SQLALCHEMY_ENGINE_OPTIONS"] = {
132-
'pool_size': 10,
133-
'pool_recycle': 120,
134-
'pool_pre_ping': True
135-
}
136-
DB.init_app(self.application)
137-
138-
ms = MyMicroservice(path=__file__)
139-
app = ms.create_app()
140-
```
141-
142-
## Example 3: Create your logger
143-
144-
The next example show how to create a personal logger for your application
145-
146-
```python
147-
import logging.config
148-
149-
from pyms.flask.app import Microservice
150-
151-
152-
class MyMicroservice(Microservice):
153-
def init_logger(self):
154-
level = "INFO"
155-
LOGGING = {
156-
'version': 1,
157-
'disable_existing_loggers': False,
158-
'formatters': {
159-
'console': {
160-
'format': '[%(asctime)s][%(levelname)s] %(name)s '
161-
'%(filename)s:%(funcName)s:%(lineno)d | %(message)s',
162-
'datefmt': '%H:%M:%S',
163-
},
164-
},
165-
'handlers': {
166-
'console': {
167-
'level': level,
168-
'class': 'logging.StreamHandler',
169-
'formatter': 'console'
170-
},
171-
},
172-
'loggers': {
173-
'': {
174-
'handlers': ['console'],
175-
'level': level,
176-
'propagate': True,
177-
},
178-
'root': {
179-
'handlers': ['console'],
180-
'level': level,
181-
'propagate': True,
182-
},
183-
}
184-
}
185-
logging.config.dictConfig(LOGGING)
186-
187-
ms = MyMicroservice(path=__file__)
188-
app = ms.create_app()
189-
```
190-
19199

192100
Check more examples in [this Github page](https://github.com/python-microservices/pyms/tree/master/examples)

docs/services.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ pyms:
7979

8080
## Tracer
8181

82-
Add trace to all executions with [opentracing](https://github.com/opentracing-contrib/python-flask).
82+
Add trace to all executions with [opentracing](https://github.com/opentracing-contrib/python-flask). This service
83+
solves the problem of [distributed tracing](https://microservices.io/patterns/observability/distributed-tracing.html)
8384

8485
### Installation
8586

0 commit comments

Comments
 (0)
0