Skip to main content

Moesif for Python Requests

by Moesif, the API analytics and API monetization platform.

Built For Latest Version Language Versions Software License Source Code

It's an interceptor for Python Requests library that captures outgoing API calls and sends to Moesif for API analytics and monitoring.

If you're new to Moesif, see our Getting Started resources to quickly get up and running.

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.

Prerequisites

Before using Moesif for Python Requests, make sure you have the following:

Get Your Moesif Application ID

After you log into Moesif Portal, you can get your Moesif Application ID during the onboarding steps. You can always access the Application ID any time by following these steps from Moesif Portal after logging in:

  1. Select the account icon to bring up the settings menu.
  2. Select Installation or API Keys.
  3. Copy your Moesif Application ID from the Collector Application ID field.
Accessing the settings menu in Moesif Portal

Install

Install with pip:

pip install moesifpythonrequest

Configure

See the available configuration options to learn how to configure moesifpythonrequest for your use case.

How to Use

Import the Moesif library and call the start_capture_outgoing method. Moesif will start logging all API calls made from the Requests library.

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

Replace YOUR_MOESIF_APPLICATION_ID with your Moesif Application ID.

Troubleshoot

For a general troubleshooting guide that can help you solve common problems, see Server Troubleshooting Guide.

Other troubleshooting supports:

Repository Structure

.
├── images/
├── LICENSE
├── MANIFEST.in
├── moesifpythonrequest/
├── README.md
├── register.py
├── requirements.txt
├── setup.cfg
└── setup.py

Configuration options

The following sections describe the available configuration options. You have to set these options in a Python dictionary and pass that as an argument as you call the start_capture_outgoing method. See the example for better understanding.

APPLICATION_ID (Required)

Data type
String

A string that identifies your application in Moesif.

GET_METADATA_OUTGOING

table>

Data type Parameters Return type Function (req, res) Dictionary

Optional.

A function that enables you to return custom metadata associated with the logged API calls.

Takes in the Requests request and response objects as arguments.

We recommend that you implement a function that returns a dictionary containing your custom metadata. The dictionary must be a valid one that can be encoded into JSON. For example, you may want to save a virtual machine instance ID, a trace ID, or a resource ID with the request.

IDENTIFY_USER_OUTGOING

Data type Parameters Return type
Function (req, res) String

Optional, but highly recommended.

A function that takes Requests request and response objects, and returns a string that represents the user ID used by your system.

While Moesif tries to identify users automatically, different frameworks and your implementation might vary. So we highly recommend that you accurately provide a user ID using this function.

IDENTIFY_COMPANY_OUTGOING

Data type Parameters Return type
Function (req, res) String

Optional.

A function that takes Requests request and response objects and returns a string that represents the company ID for this event.

GET_SESSION_TOKEN_OUTGOING

Data type Parameters Return type
Function (req, res) String

Optional.

A function that takes Requests request and response objects, and returns a string that corresponds to the session token for this event.

Similar to user IDs, Moesif tries to get the session token automatically. However, if you setup differs from the standard, this function can help tying up events together and help you replay the events.

LOG_BODY_OUTGOING

Data type Default
Boolean True

Optional.

Set to False to remove logging request and response body.

SKIP_OUTGOING

Data type Parameters Return type
Function (req, res) Boolean

Optional.

A function that takes a Requests request and response objects, and returns True if you want to skip this particular event.

MASK_EVENT_MODEL

Data type Parameters Return type
Function (EventModel) EventModel

Optional.

A function that takes the final Moesif event model and returns an EventModel object with desired data removed.

For more information about Moesif event model, see Moesif Python API documentation.

Examples

An example Moesif integration is available on GitHub.

How to Get Help

If you face any issues, try the troubheshooting guidelines. For further assistance, reach out to our support team.

Explore Other Integrations

Explore other integration options from Moesif:

Release files for moesifpythonrequest 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moesifpythonrequest 0.3.5
File Size Uploaded
moesifpythonrequest-0.3.5.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moesifpythonrequest 0.3.5
File Interpreter ABI Platform
moesifpythonrequest-0.3.5-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 34.0 kB

Release files / moesifpythonrequest-0.3.5.tar.gz

Download URL moesifpythonrequest-0.3.5.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9a2a1a4af9dbf6265d353d5f47fc6b7b54a23869a8be74782b42a7949aec28c6
BLAKE2b-256 checksum
How to use checksums
d09dcea8f561f1023f94a23e35c4935bd7aa1b255f03ea3a515396152c2ec452
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.18

Release files / moesifpythonrequest-0.3.5-py2.py3-none-any.whl

Download URL moesifpythonrequest-0.3.5-py2.py3-none-any.whl
Size 16.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0a39bedf8daabf8edbe4b03e0e8c343c12ec4de0cea6b0500a7b8284e36c4931
BLAKE2b-256 checksum
How to use checksums
ae76140d25cec10675a931b33604fc8a9772815754052a55287dbfc535998420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.12

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page