M360 middleware library for Python Django and Flask
Project description
m360.mw.python
The M360 Python Middleware is a dependency that gets consumed by a Python Web Server built using one of these frameworks Django and Flask.
The middleware is developed using native Python and includes interfaces that facilitate using it with the above mentioned frameworks.
Installation
pip install m360-middleware
Usage
Django
In your settings.py file, include the middleware and its configuration:
import os
# ...
MIDDLEWARE = [
# ...
# -------------------- M360 Middleware Setup --------------------
'm360.frameworks.django.middleware.DjangoMiddleware',
# ...
]
# ...
M360 = {
"contract": os.path.join(os.path.dirname(__file__), "./contract.json"),
"ip": os.environ.get('APP_IP') or "127.0.0.1",
"type": "django",
"platform": "manual"
}
In your views, import and use the middleware:
from django.http import JsonResponse
# the sdk is initialized using the middleware when Django starts
from m360 import sdk
M360 = sdk.instance()
def get_settings(request):
return JsonResponse(M360.registry.get(), status=200, safe=False)
Flask
In your settings.py file, include the middleware and its configuration:
import os
# ...
app = Flask(__name__)
from m360.frameworks.flask.middleware import FlaskMiddleware
app.wsgi_app = FlaskMiddleware(app.wsgi_app, {
"contract": os.path.join(os.path.dirname(__file__), "./contract.json"),
"ip": os.environ.get('APP_IP') or "127.0.0.1",
"type": "flask",
"platform": "manual"
})
In your views, import and use the middleware:
# the sdk is initialized using the middleware when Flask starts
import json
from m360 import sdk
M360 = sdk.instance()
@app.route('/m360/settings', methods=['GET', 'POST'])
def m360_settings():
return json.dumps(M360.registry.get())
Containerized Deployment
Deploying on Docker
When deploying on Docker, please provide the extra options below. Without these options, the handshake between the middleware and the gateway will fail, along with any maintenance operation that gets triggered from the console onto this microservice.
Replace the platform:manual
with platform:docker
and add the below.
Option | Data Type | Mandatory | Description |
---|---|---|---|
platform | String | YES | value equals 'docker' |
network | String | YES | value equals the docker network attached to this docker service |
service | String | YES | value equals the name of the docker service |
containerIP | String | NO | value is the internal IP address of the docker container in the docker service |
Example
'platform': 'docker',
'platformOptions': {
'network': 'mike',
'service': 'service-express',
'containerIP': '127.0.0.1'
}
Deploying on Kubernetes
When deploying on Kubernetes, please provide the extra options below. Without these options, the handshake between the middleware and the gateway will fail, along with any maintenance operation that gets triggered from the console onto this microservice.
Replace the platform:manual
with platform:kubernetes
and add the below.
Option | Data Type | Mandatory | Description |
---|---|---|---|
platform | String | YES | value equals 'kubernetes' |
namespace | String | YES | value equals the kubernetes namespace where your deployment will run |
service | String | YES | value equals the name of the kubernetes service that is attached to the your deployment |
exposedPort | String | YES | value equals the exposed port kubernetes service |
'platform': 'kubernetes',
'platformOptions": {
'namespace': 'mike',
'service': 'service-express',
'exposedPort': 30402
}
Notes
The Middleware includes samples on how you can consume it with both Django and Flask.
These sample apps are located inside the examples folder in this repository.
Reference: M360 Middleware Official Documentation
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file m360-middleware-0.0.2.tar.gz
.
File metadata
- Download URL: m360-middleware-0.0.2.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560dc48be53dd2fede4e8fedd0bd47e6efc7e38fb8ce6f503623879360e529ab |
|
MD5 | 848f7ce2724d44ff0e03441cc0f20059 |
|
BLAKE2b-256 | 5d8fc01624c9909c1e285fe73d5465ef435154f55936a4aa9334af76017a4835 |
File details
Details for the file m360_middleware-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: m360_middleware-0.0.2-py3-none-any.whl
- Upload date:
- Size: 43.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bdcaf99ce15abdcfb1dba991afd2b5e07210c4de4af31985292313c9c744b3f |
|
MD5 | 9a9288459840bc51761014434cab02f8 |
|
BLAKE2b-256 | 99cf9cf7bd0d3f213f3fbaa6e130b16353a62b35671c2439f8db19b539df9b80 |