Moesif Python request
Project description
Moesif Python Requests
Interceptor for Python Requests lib to capture outgoing API calls and sends to Moesif for API analytics and monitoring.
If you are using Moesif's API monitoring SDKs like Moesif Django or Moesif WSGI to log incoming API calls, this library is already included.
How to install
pip install moesifpythonrequest
Import the Moesif lib and call start_capture_outgoing. Moesif will start logging all API calls made from the requests lib.
from moesifpythonrequest.start_capture.start_capture import StartCapture
import requests
moesif_settings = {
'APPLICATION_ID': 'Your Moesif Application Id'
}
def main():
# Outgoing API call to third party like Github / Stripe or to your own dependencies
response = requests.get("http://httpbin.org/uuid")
print(response.json())
StartCapture().start_capture_outgoing(moesif_settings)
main()
Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
Configuration options
APPLICATION_ID
(required) string, Your Moesif Application Id which can be found by logging into the Moesif Portal, click on the top right menu, and then clicking Installation.
GET_METADATA_OUTGOING
(optional) (req, res) => dictionary, a function that enables you to return custom metadata associated with the logged API calls. Takes in the Requests request and response object as arguments. You should implement a function that returns a dictionary containing your custom metadata. (must be able to be encoded into JSON). For example, you may want to save a VM instance_id, a trace_id, or a resource_id with the request.
IDENTIFY_USER_OUTGOING
(optional, but highly recommended) (req, res) => string, a function that takes Requests request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically, but different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.
IDENTIFY_COMPANY_OUTGOING
(optional) (req, res) => string, a function that takes Requests request and response, and returns a string that is the company id for this event.
GET_SESSION_TOKEN_OUTGOING
(optional) (req, res) => string, a function that takes Requests request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.
LOG_BODY_OUTGOING
(optional) boolean, default True, Set to False to remove logging request and response body.
SKIP_OUTGOING
(optional) (req, res) => boolean, a function that takes a Requests request and response, and returns true if you want to skip this particular event.
MASK_EVENT_MODEL
(optional) (EventModel) => EventModel, a function that takes a Moesif EventModel and returns an EventModel with desired data removed. For details regarding EventModel please see the Moesif Python API Documentation.
Example
An example Moesif integration is available on GitHub
Other integrations
To view more documentation on integration options, please visit the Integration Options Documentation.
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
Built Distribution
Hashes for moesifpythonrequest-0.3.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a50b18353eb9f36179179d216f4e28aa735c27c9b17b3027e6fca02177237b25 |
|
MD5 | 76874c9b19cebb071201e1b9cb4be3a1 |
|
BLAKE2b-256 | 65f299b80205969bbcc471faaf686d8d674ae6add5741d405307d65f2200b0b9 |
Hashes for moesifpythonrequest-0.3.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67ec24cabd43804a2fbdba8e5bb49b7e9a954b61476614af7546b7df96c71db7 |
|
MD5 | 99ce21900a3cb238b559db577480026e |
|
BLAKE2b-256 | 6e1b98e07204f49039362f2a26f73b3e3f5b395b4481105af409400e38e2f204 |