Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Utility library for Kantopark's python instances

Project description

Kantopark Python

This package contains Kantopark's python utility functions. The functions and types inside make it easier to develop Python instances.

Installation

pip install kantopy

Usage

A typical function is listed below.

import json

def my_func(event):
    payload = event.json
    # some operations with the payload later
    # ...
    return json.dumps(payload)

Since Kantopark's python function must always return a string or byte object (data transferred over the web are essentially byte data after all), it might be tedious to use json.dumps(...).

With kantopy, here's how the above can be re-written

from kantopy import Event, as_json

def my_func(event: Event):  # notice the typings here
    payload = event.json  # minimize misspelling with typings
    # some operations later
    # ...
    return as_json(payload)

If you're returning a graph (matplotlib or plotly), here's how you can use it.

from kantopy import Event, as_png
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

def create_figure():
    fig = Figure()
    axis = fig.add_subplot(1, 1, 1)
    xs = range(100)
    ys = [x * 2 + 3 for x in xs]
    axis.plot(xs, ys)  # just a straight line
    return fig

def my_func(event: Event):
    fig = create_figure()
    return as_png(fig)  # this would return the output as a png image

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
kantopy-0.0.1-py3-none-any.whl (2.6 kB) Copy SHA256 hash SHA256 Wheel py3
kantopy-0.0.1.tar.gz (2.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page