Skip to main content

A Flask SDK for Apitoolkit integration

Project description

API Toolkit Python Flask SDK

The API Toolkit Flask client is an sdk used to integrate flask web services with APIToolkit. It monitors incoming traffic, gathers the requests and sends the request to the apitoolkit servers.

Design decisions:

  • Use the gcp SDK to send real time traffic from REST APIs to the gcp topic

How to Integrate:

First install the apitoolkit flask sdk: pip install apitoolkit-flask

Then add apitoolkit to your app like so (flask example):

from flask import Flask
from apitoolkit import APIToolkit

app = Flask(__name__)

apitoolkit = APIToolkit(api_key="<API_KEY>", debug=True)


@app.before_request
def before_request():
    apitoolkit.beforeRequest()

@app.after_request
def after_request(response):
    apitoolkit.afterRequest(response)
    return response


@app.route('/hello', methods=['GET', 'POST'])
def sample_route(subject):
    return {"Hello": "World"}

app.run(debug=True)

This will monitor all requests and send them to the APIToolkit's servers.

Client Redacting fields

While it's possible to mark a field as redacted from the apitoolkit dashboard, this client also supports redacting at the client side. Client side redacting means that those fields would never leave your servers at all. So you feel safer that your sensitive data only stays on your servers.

To mark fields that should be redacted, add them to the APIToolkit constructor. Eg:

from flask import Flask
from apitoolkit import APIToolkit

app = Flask(__name__)

# A list of fields to redact from response body
redact_res = ["$.api_key", "$.password"]
# A list of fields to redact from request body
redact_req = ["$.credit-card.cvv", "$.credit-card.name"]
# A list of fields to redact from request and repsonse headers
redact_headers = ["Authorization", "Cookie"]

apitoolkit = APIToolkit(api_key="<API_KEY>", debug=True,redact_response_body=redact_res, redact_request_body=redact_req,redact_headers=redact_headers)

@app.before_request
def before_request():
    apitoolkit.beforeRequest()

@app.after_request
def after_request(response):
    apitoolkit.afterRequest(response)
    return response


@app.route('/hello', methods=['GET', 'POST'])
def sample_route(subject):
    return {"Hello": "World"}

app.run(debug=True)

It is important to note that while the redact_headers config field accepts a list of headers(case insensitive), the redact_request_body and redact_response_body expect a list of JSONPath strings as arguments.

The choice of JSONPath was selected to allow you have great flexibility in descibing which fields within your responses are sensitive. Also note that these list of items to be redacted will be aplied to all endpoint requests and responses on your server. To learn more about jsonpath to help form your queries, please take a look at this cheatsheet: https://lzone.de/cheat-sheet/JSONPath

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

apitoolkit_flask-0.1.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

apitoolkit_flask-0.1.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file apitoolkit_flask-0.1.2.tar.gz.

File metadata

  • Download URL: apitoolkit_flask-0.1.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for apitoolkit_flask-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d40551b2d023e7306f0496e75471b62f43d215ccfc67889ac3f5752eb83fbc10
MD5 fa632ec5435a946f5ddf935332ff89e1
BLAKE2b-256 3872c2e95065be470aa765f3aa505b6926bd2c815e811760c72a8989775402e2

See more details on using hashes here.

File details

Details for the file apitoolkit_flask-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for apitoolkit_flask-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba8f46df3dd9b3fab3c8487db12c82c66ebb07530cefc173842200050fa9f559
MD5 b6105a8b5fd8f1f30240cd0febee539b
BLAKE2b-256 c1b05f2317bb030d15575169a518705608d68afa2c444e3648bd6a5dc3215864

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