Skip to main content

REST microservice framework based on Flask, OpenAPI, gunicorn and celery, deployable towards GKE and Beanstalk

Project description

pymacaron logo

Pymacaron

Python microservice framework based on Flask, OpenAPI and Celery, deployable on GKE and Beanstalk

PyMacaron's documentation is available at http://pymacaron.com/.

This page dives deeper into internal implementation details.

Deep dive

Built-in endpoints

The following endpoints are built-in into every pymacaron instance, based on this swagger specification:

# Assuming you did in a separate terminal:
# $ python server.py --port 8080

$ curl http://127.0.0.1:8080/ping
{}

$ curl http://127.0.0.1:8080/version
{
  "apis":["ping"],
  "name": "helloworld",
  "pym_env":"staging",
  "version": "220120-2219-3820-a6f45b",
}

$ curl http://127.0.0.1:8080/auth/version
{
  "error_description": "There is no Authorization header in the HTTP request",
  "error_id": "17f900c8-b456-4a64-8b2b-83c7d36353f6",
  "status": 401,
  "error": "AUTHORIZATION_HEADER_MISSING"
}

$ curl -H "Authorization: Bearer eyJpc3M[...]y8kNg" http://127.0.0.1:8080/auth/version
{
  "apis":["ping"],
  "name": "helloworld",
  "pym_env":"staging",
  "version": "220120-2219-3820-a6f45b",
}

Loading api clients from a standalone script

It may come very handy within a standalone script to be able to call REST apis through the pymacaron framework, to get object marshalling and error handling out of the box. It is done as follows:

import flask
from pymacaron import apipool
from pymacaron.exceptions import is_error

# Declare a Flask app and mock its context
app = flask.Flask(__name__)
with app.test_request_context(''):

    # Then load client libraries against a given set of libraries
    api = API(app)
    api.load_clients(apis=['login', 'search'])

    # And you can now call those apis seamlessly!
    result = ApiPool.login.client.do_login(
        ApiPool.login.model.LoginData(
            name='foobar',
            password='youdontwanttoknow'
        )
    )

    if is_error(result):
        log.error("Oops. Failed to login user")

Author

Erwan Lemonnier
github.com/pymacaron
github.com/erwan-lemonnier
www.linkedin.com/in/erwan-lemonnier/

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

pymacaron-2.0.345.tar.gz (44.4 kB view details)

Uploaded Source

File details

Details for the file pymacaron-2.0.345.tar.gz.

File metadata

  • Download URL: pymacaron-2.0.345.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.3 requests/2.28.1 setuptools/65.3.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.13

File hashes

Hashes for pymacaron-2.0.345.tar.gz
Algorithm Hash digest
SHA256 61ea65fdd8a2ca52f247bb653c0e891abbe2cbe01b0916b1f49dae3758801417
MD5 d3833c66c5fa7731cf97a10d6a82e9b1
BLAKE2b-256 1813dd652706c6bead1829fc075855591c8b6057e6260df5ff98b233aac392c6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page