A micro-framework for the OMG, and code written in Python 3.6+.
Project description
OMG: Micro Framework
A micro-framework for the excellent Open Microservices Guide, for suppportive code written in Python 3.6+.
Note: this is pre-release software, and is subject to improvement. Contributions are welcome!
Intended / Example Usage
$ cat service.py
import micro
from uuid import uuid4
service = micro.Service(name='uuid')
@service.register()
def new(prefix: str) -> str:
"""Generates a UUID, with a given prefix."""
return f'{prefix}{uuid4().hex}'
# Alternative Syntax:
# service.add(f=new)
if __name__ == '__main__':
service.serve(ensure=True)
If not available on disk, the required Dockerfile
and microservice.yml
files will automatically be generated, for your application:
$ cat microservice.yml
actions:
new:
help: Generates a UUID, with a given prefix.
arguments:
prefix:
in: query
required: true
type: string
http:
method: get
path: /new
port: 8080
output:
type: string
lifecycle:
startup:
command:
- python3
- /app/service.py
omg: 1
$ cat Dockerfile
FROM kennethreitz/pipenv
COPY . /app
CMD ["python3", "service.py"]
Now, run your microservice!
$ python service.py
2019-05-09 14:45:39,342 - micro - DEBUG - Initiating 'uuid' service.
2019-05-09 14:45:39,344 - micro - DEBUG - Registering Flask endpoint: '/uuid4'
2019-05-09 14:45:39,344 - micro - DEBUG - Dockerfile './Dockerfile' already exists!
2019-05-09 14:45:39,345 - micro - DEBUG - Microservice Manifest './microservice.yml' already exists!
2019-05-09 14:45:39,346 - micro - INFO - Serving on: '*:8080'
This will spawn a Flask application (using the production-ready waitress web server), preconfigured to serve the masses!
Or, use the omg-cli:
$ omg run uuid4 -a prefix='user-'
…
Installation
$ pip install omg-micro
P.S. Do provide feedback, if you desire! :)
✨ 🍰 ✨
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
omg-micro-0.3.0.tar.gz
(6.7 kB
view hashes)
Built Distribution
Close
Hashes for omg_micro-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d17051e119c3eebbefc5742c8d024945c4dc252f3475d62efc8b393760d3c241 |
|
MD5 | 05dce1b3350ee84b04b8140c449ab05c |
|
BLAKE2b-256 | 21242313bc692e9ca9dc573e9c63fc92b3b2141bbaeff7fac47ff7cdb1e7a7ed |