Skip to content
10 changes: 5 additions & 5 deletions docs/command_line.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Commnand line

PyMS has some command to make easy your developments:
PyMS comes with some commands to make your developments easier:

```bash
pyms -h
```
Show you a list of options and help instructions to use this command like:
Lists the options and help instructions to use this command:

```bash
usage: main.py [-h] [-v VERBOSE]
Expand Down Expand Up @@ -37,11 +37,11 @@ Command:
pyms startproject
```

This command create a project template like [Microservices Scaffold](https://github.com/python-microservices/microservices-scaffold).
This command use [cookiecutter](https://github.com/cookiecutter/cookiecutter) to download and install this [template](https://github.com/python-microservices/microservices-template)
This command creates a project template like the one defined in [Microservices Scaffold](https://github.com/python-microservices/microservices-scaffold).
This command uses [cookiecutter](https://github.com/cookiecutter/cookiecutter) to download and install this [template](https://github.com/python-microservices/microservices-template)

!!! warning
You must run first `pip install cookiecutter==1.7.0`
First, you must run `pip install cookiecutter==1.7.0`

## Create a key encrypt/decrypt file

Expand Down
44 changes: 22 additions & 22 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

## Environments variables of PyMS:

**CONFIGMAP_FILE**: The path to the configuration file. By default, PyMS search the configuration file in your
actual folder with the name "config.yml"
**KEY_FILE**: The path to the key file to decrypt your configuration. By default, PyMS search the configuration file in your
actual folder with the name "key.key"
**CONFIGMAP_FILE**: The path to the configuration file. By default, PyMS searches for the configuration file in your
current folder with the name "config.yml"
**KEY_FILE**: The path to the key file to decrypt your configuration. By default, PyMS searches for the configuration file in your
current folder with the name "key.key"

## Create configuration
Each microservice needs a config file in yaml or json format to work with it. This configuration contains
the Flask settings of your project and the [Services](services.md). With this way to create configuration files, we
Each microservice needs a config file in yaml or json format for it to work with. This configuration contains
the Flask settings of your project and the [Services](services.md). With this way of creating configuration files, we
solve two problems of the [12 Factor apps](https://12factor.net/):

- Store config out of the code
- Dev/prod parity: the configuration could be injected and not depends of our code, for example, Kubernetes configmaps
- Dev/prod parity: the configuration could be injected and doesn't depend on our code, for example, Kubernetes configmaps

a simple configuration file could be a config.yaml:
A simple configuration file could be a config.yaml:

```yaml
pyms:
Expand Down Expand Up @@ -60,32 +60,32 @@ or in a config.json:
}
```

This file could contains this keywords:
This file can contain the following keywords:

## pyms - services block

```pyms```: all subsets inside this keyword are the settings of this library. Each keyword will be a service of our
[Microservice class](ms_class.md). For example, we declare our microservice class as:
[Microservice class](ms_class.md). For example, if we declare our microservice class as:

```python
from pyms.flask.app import Microservice
ms = Microservice(path=__file__)
```
and a `config.yaml` file:
and have a `config.yaml` file such as:

```yaml
pyms:
services:
requests: true
```

our object `ms` has an attribute `requests` that is a instance of our service [requests](services.md).
our `ms` object will have an attribute `requests` that is a instance of our service [requests](services.md).

## pyms - config block
This part contains all keywords of a [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/) and our
constants of the enviroments (local configuration, staging configuration...). Keep in mind that a Flask configuration needs
the keywords to be declared as uppercase. If you defined a variable like `app_name`, you will get this with
`current_app.config["APP_NAME"]`
This section contains all keywords used for general [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/), along
with our constants for the different enviroments (local configuration, staging configuration...). Keep in mind that
a Flask app configuration needs the keywords to be declared as uppercase. If you defined a variable like `app_name`,
you will be able to retrieve it with `current_app.config["APP_NAME"]`


## Import Configuration
Expand All @@ -98,7 +98,7 @@ def my_endpoint():
print(current_app.config["DEBUG"])
```

But, what happend if you need the configuration BEFORE Flask class is instanced? Imagine this case:
But, what happens if you need to access the configuration BEFORE Flask class is instanced? Imagine this case:

```python
from flask import Blueprint, current_app
Expand All @@ -115,7 +115,7 @@ API = Api(
)
```

This raise a `'working outside of application context` error. Who can solve this problem?
This raises a `'working outside of application context` error. Who can solve this problem?

```python
from flask import Blueprint, current_app
Expand All @@ -135,10 +135,10 @@ API = Api(


## Looking for Configuration file with Kubernetes Configmaps
By default, Microservice class search a config.yml in the same path. You can set a different route or set a json file.
To change this path, define a environment variable `CONFIGMAP_FILE`.
By default, the Microservice class searches for a config.yml in the same path. You can set a different route or set a json file.
To change this path, you must define an environment variable called `CONFIGMAP_FILE`.

This way of looking for the configuration is useful when you work with Docker and Kubernetes. For example, you can integrate
This way of looking for the configuration is useful when you work with Docker and Kubernetes. For example, you could integrate
a configmap of Kubernetes, with this microservice and a deployment with:

```yaml
Expand Down Expand Up @@ -166,4 +166,4 @@ spec:
name: my-microservice-configmap
```

See [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
See [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
26 changes: 12 additions & 14 deletions docs/encrypt_decryt_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


When you work in multiple environments: local, dev, testing, production... you must set critical configuration in your
variables, like:
variables, such as:

config.yml, for local propose:
```yaml
Expand All @@ -32,8 +32,8 @@ pyms:

You can move this file to a [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/),
use [Vault](https://learn.hashicorp.com/vault) or encrypt the configuration with [AWS KMS](https://aws.amazon.com/en/kms/)
or [Google KMS](https://cloud.google.com/kms). We strongly recommended this ways to encrypt/decrypt your configuration,
but if you want a no vendor locking option or you haven`t the resources to use this methods, we create a way to encrypt
or [Google KMS](https://cloud.google.com/kms). We strongly recommend these way of encrypting/decrypting your configuration,
but if you don't want a vendor locking option or you don't have the resources to use these methods, we provide a way to encrypt
and decrypt your variables.

## 1. Generate a key
Expand All @@ -47,20 +47,20 @@ pyms create-key
Then, type a password and it will create a file called `key.key`. This file contains a unique key. If you loose this file
and re-run the create command, the key hash will be different and your code encrypted with this key won't be able to be decrypted.

Store the key in a secure site, and NOT COMMIT this key to your repository.
Store this key in a secure site, and DO NOT COMMIT it to your repository.


## 2. Add your key to your environment

Move, for example, your key to `mv key.key /home/my_user/keys/myproject.key`
Move your key, for example, to `mv key.key /home/my_user/keys/myproject.key`

then, store this key in a environment variable with:
then, store the key in a environment variable with:

```bash
export KEY_FILE=/home/my_user/keys/myproject.key
```

## 3. Encrypt your information and put in config
## 3. Encrypt your information and store it in config

Do you remember the example file `config_pro.yml`? Now you can encrypt and decrypt the information, you can run the command
`pyms encrypt [string]` to generate a crypt string, for example:
Expand All @@ -70,7 +70,7 @@ pyms encrypt 'mysql+mysqlconnector://important_user:****@localhost/my_schema'
>> Encrypted OK: b'gAAAAABeSwBJv43hnGAWZOY50QjBX6uGLxUb3Q6fcUhMxKspIVIco8qwwZvxRg930uRlsd47isroXzkdRRnb4-x2dsQMp0dln8Pm2ySHH7TryLbQYEFbSh8RQK7zor-hX6gB-JY3uQD3IMtiVKx9AF95D6U4ydT-OA=='
```

And put this string in your `config_pro.yml`:
And store this string in your `config_pro.yml`:
```yaml
pyms:
crypt:
Expand All @@ -88,9 +88,9 @@ can find the answer

## 4. Decrypt from your config file

Pyms knows if a variable is encrypted if this var start with the prefix `enc_` or `ENC_`. PyMS searchs for your key file
in the `KEY_FILE` env variable and decrypt this value and store it in the same variable without the `enc_` prefix,
por example,
Pyms knows if a variable is encrypted if this var start with the prefix `enc_` or `ENC_`. PyMS searches for your key file
in the `KEY_FILE` env variable and decrypts this value to store it in the same variable without the `enc_` prefix,
for example,

```yaml
ENC_SQLALCHEMY_DATABASE_URI: gAAAAABeSwBJv43hnGAWZOY50QjBX6uGLxUb3Q6fcUhMxKspIVIco8qwwZvxRg930uRlsd47isroXzkdRRnb4-x2dsQMp0dln8Pm2ySHH7TryLbQYEFbSh8RQK7zor-hX6gB-JY3uQD3IMtiVKx9AF95D6U4ydT-OA==
Expand All @@ -102,7 +102,7 @@ Will be stored as
SQLALCHEMY_DATABASE_URI: mysql+mysqlconnector://user_of_db:user_of_db@localhost/my_schema
```

And you can access to this var with `current_app.config["SQLALCHEMY_DATABASE_URI"]`
And you can access this var with `current_app.config["SQLALCHEMY_DATABASE_URI"]`

# Method 2: Encrypt and decrypt with AWS KMS

Expand Down Expand Up @@ -143,5 +143,3 @@ pyms:
ENC_SQLALCHEMY_DATABASE_URI: "AQICAHiALhLQv4eW8jqUccFSnkyDkBAWLAm97Lr2qmdItkUCIAF+P4u/uqzu8KRT74PsnQXhAAAAoDCBnQYJKoZIhvcNAQcGoIGPMIGMAgEAMIGGBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDPo+k3ZxoI9XVKtHgQIBEIBZmp7UUVjNWd6qKrLVK8oBNczY0CfLH6iAZE3UK5Ofs4+nZFi0PL3SEW8M15VgTpQoC/b0YxDPHjF0V6NHUJcWirSAqKkP5Sz5eSTk91FTuiwDpvYQ2q9aY6w=
"
```


8 changes: 4 additions & 4 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Open in your browser http://localhost:5000/

## Example 2: Create your Microservice class

Create a class that inherit from `pyms.flask.app.Microservice` and override methods with your own configuration.
Create a class that inherits from `pyms.flask.app.Microservice` and overrides methods with your own configuration.
The next example show how to innit a lib like [Flask Babel](https://pythonhosted.org/Flask-Babel/)

main.py:
Expand All @@ -63,7 +63,7 @@ app = ms.create_app()

## Example 2: Initialize SQLAlchemy

The next example show how to innit a lib like [Flask SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/)
The next example shows us how to innit a lib like [Flask SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/)

config.yml:

Expand Down Expand Up @@ -99,7 +99,7 @@ app = ms.create_app()

## Example 3: Create your logger

The next example show how to create a personal logger for your application
The next example shows us how to create a personal logger for your application

```python
import logging.config
Expand Down Expand Up @@ -146,4 +146,4 @@ ms = MyMicroservice(path=__file__)
app = ms.create_app()
```

See [this Github page](https://github.com/python-microservices/pyms/tree/master/examples) to see a examples
See [this Github page](https://github.com/python-microservices/pyms/tree/master/examples) to see more examples
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ Get started with [Installation](installation.md) and then get an overview with t

## Motivation

When we started to create microservice with no idea, we were looking for tutorials, guides, best practices, but we found
When we started to create a microservice with no previous knowledge, we started 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?
But... what happens when we want our configuration out of the code, such as a 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.
There are many problems around Python and microservices and we couldn't find anyone to give us a solution.

We start creating these projects to try to solve all the problems we have found in our professional lives about
microservices architecture.
Expand Down
10 changes: 5 additions & 5 deletions docs/ms_class.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Microservices class

The class Microservice is the core of all microservices built with PyMS.
The Microservice class is the core of all microservices built with PyMS.


You can create a simple microservice such as:
Expand Down Expand Up @@ -30,9 +30,9 @@ pyms:
config:
APP_NAME: "Python Microservice"
```
Check [Configuration](configuration.md) section to know how to create a configuration file.
Check the [Configuration](configuration.md) section to learn how to create a configuration file.

`Microservice` class search for a `config.yml` in the directory you pass in `path` parameter or search the file in
The `Microservice` class searches for a `config.yml` in the directory you pass in `path` parameter or looks for the file in
`CONFIGMAP_FILE` env var.

Each keyword in our configuration block, can be accessed in our Microservice object through the attribute `config`.
Expand Down Expand Up @@ -67,7 +67,7 @@ print(ms.config.multiplevars.config2)

## Personalize your microservices

Microservice class initialize the libraries and other process by this way:
The Microservice class initializes libraries and other process in the following way:

```python
...
Expand Down Expand Up @@ -97,4 +97,4 @@ Microservice class initialize the libraries and other process by this way:
```


Check more examples in [this Github page](https://github.com/python-microservices/pyms/tree/master/examples)
Check for more examples in [this Github page](https://github.com/python-microservices/pyms/tree/master/examples)
20 changes: 10 additions & 10 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.

You need to create 2 files: main.py and config.yml:
To start out, you need to create 2 files: main.py and config.yml:

main.py
```python
Expand Down Expand Up @@ -38,20 +38,20 @@ pyms:

## So what did that code do?

1. Create a instance of PyMS Microservice class (#1.1). This initialization inject the configuration defined in the
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.
1. Create a instance of PyMS Microservice class (#1.1). This initialization injects the configuration defined in the
1.3 block, so it could be accessed through current_app.config. Then, it initializes the service defined in the 1.2 block. See [Services](services.md) for more details.
2. Initialize [Flask](https://flask.palletsprojects.com/en/1.1.x/) instance, [Connexion](https://github.com/zalando/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` return the flask instance and you can interact with it as a typical flask app
`ms` attribute and you can access to it with `current_app.ms`. These steps all have their own functions and you can easy override any of them.
3. `create_app` returns the flask instance and you can interact with it as a typical flask app

# Create a project from scaffold

PyMS has a command line option to create a project template like [Microservices Scaffold](https://github.com/python-microservices/microservices-scaffold).
This command use [cookiecutter](https://github.com/cookiecutter/cookiecutter) to download and install this [template](https://github.com/python-microservices/microservices-template)
This command uses [cookiecutter](https://github.com/cookiecutter/cookiecutter) to download and install this [template](https://github.com/python-microservices/microservices-template)

!!! warning
You must run first `pip install cookiecutter==1.7.0`
First, you must run `pip install cookiecutter==1.7.0`

## Installation

Expand All @@ -60,7 +60,7 @@ pyms startproject
`
``

this output a lot of options step by step
this outputs a lot of options step by step

```bash
project_repo_url [https://github.com/python-microservices/microservices-scaffold]:
Expand All @@ -82,6 +82,6 @@ Select open_source_license:
Choose from 1, 2, 3, 4, 5, 6 [1]:
```

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

See [Configuration](configuration.md), [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
See [Configuration](configuration.md), [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
4 changes: 2 additions & 2 deletions docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Now, you can create a `swagger.yaml` file with [OpenAPI Specification](https://s

# Examples of routing

You can see how structure a project or OpenAPI Specification in
You can see how to structure a project or OpenAPI Specification in
[PyMS examples](https://github.com/python-microservices/pyms/tree/master/examples/microservice_swagger) or in
[Microservice Scaffold](https://github.com/python-microservices/microservices-scaffold)

## Routing to files

This section is equal from [Zalando Connexion](https://github.com/zalando/connexion#automatic-routing), because PyMS use
This section is equal to [Zalando Connexion](https://github.com/zalando/connexion#automatic-routing), because PyMS uses
this library to route endpoints to functions:

**Explicit Routing**:
Expand Down
Loading