Moesif Python Requests

Built For Latest Version Language Versions Software License Source Code

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("")


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


(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.


(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.


(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.


(optional) (req, res) => string, a function that takes Requests request and response, and returns a string that is the company id for this event.


(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.


(optional) boolean, default True, Set to False to remove logging request and response body.


(optional) (req, res) => boolean, a function that takes a Requests request and response, and returns true if you want to skip this particular event.


(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.


An example Moesif integration is available on GitHub

Other integrations

To view more documentation on integration options, please visit the Integration Options Documentation.