moesifpythonrequest


Namemoesifpythonrequest JSON
Version 0.3.4 PyPI version JSON
download
home_pagehttps://www.moesif.com/docs
SummaryMoesif Python request
upload_time2024-10-29 21:13:32
maintainerNone
docs_urlNone
authorMoesif, Inc
requires_pythonNone
licenseApache Software License
keywords moesif python request monkey patch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Moesif for Python Requests
by [Moesif](https://moesif.com), the [API analytics](https://www.moesif.com/features/api-analytics) and [API monetization](https://www.moesif.com/solutions/metered-api-billing) platform.

[![Built For][ico-built-for]][link-built-for]
[![Latest Version][ico-version]][link-package]
[![Language Versions][ico-language]][link-language]
[![Software License][ico-license]][link-license]
[![Source Code][ico-source]][link-source]

It's an interceptor for Python Requests library that captures outgoing API calls and sends to [Moesif](https://www.moesif.com) for API analytics and monitoring.

> If you're new to Moesif, see [our Getting Started](https://www.moesif.com/docs/) resources to quickly get up and running.

> If you are using Moesif's API monitoring SDKs like [Moesif Django](https://github.com/Moesif/moesifdjango) or [Moesif WSGI](https://github.com/moesif/moesifwsgi) to log incoming API calls, this library is already included.

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

- [An active Moesif account](https://moesif.com/wrap)
- [A Moesif Application ID](#get-your-moesif-application-id)

### Get Your Moesif Application ID
After you log into [Moesif Portal](https://www.moesif.com/wrap), 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.
<img class="lazyload blur-up" src="images/app_id.png" width="700" alt="Accessing the settings menu in Moesif Portal">

## Install
Install with pip:

```shell
pip install moesifpythonrequest
```

## Configure
See the available [configuration options](#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.

```python
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](#get-your-moesif-application-id).

## Troubleshoot
For a general troubleshooting guide that can help you solve common problems, see [Server Troubleshooting Guide](https://www.moesif.com/docs/troubleshooting/server-troubleshooting-guide/).

Other troubleshooting supports:

- [FAQ](https://www.moesif.com/docs/faq/)
- [Moesif support email](mailto:support@moesif.com)

## 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](https://github.com/Moesif/moesif-python-outgoing-example/blob/master/main.py#L31) for better understanding.

### `APPLICATION_ID` (Required)
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
  </tr>
  <tr>
   <td>
    String
   </td>
  </tr>
</table>

A string that [identifies your application in Moesif](#get-your-moesif-application-id).

### `GET_METADATA_OUTGOING`
table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Parameters
   </th>
   <th scope="col">
    Return type
   </th>
  </tr>
  <tr>
   <td>
    Function
   </td>
   <td>
    <code>(req, res)</code>
   </td>
   <td>
    Dictionary
   </td>
  </tr>
</table>

Optional.

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

Takes in the [Requests](http://docs.python-requests.org/en/master/api/) 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`
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Parameters
   </th>
   <th scope="col">
    Return type
   </th>
  </tr>
  <tr>
   <td>
    Function
   </td>
   <td>
    <code>(req, res)</code>
   </td>
   <td>
    String
   </td>
  </tr>
</table>

Optional, but highly recommended.

A function that takes [Requests](http://docs.python-requests.org/en/master/api/) 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`
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Parameters
   </th>
   <th scope="col">
    Return type
   </th>
  </tr>
  <tr>
   <td>
    Function
   </td>
   <td>
    <code>(req, res)</code>
   </td>
   <td>
    String
   </td>
  </tr>
</table>

Optional.

A function that takes [Requests](http://docs.python-requests.org/en/master/api/) request and response objects and returns a string that represents the company ID for this event.


### `GET_SESSION_TOKEN_OUTGOING`
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Parameters
   </th>
   <th scope="col">
    Return type
   </th>
  </tr>
  <tr>
   <td>
    Function
   </td>
   <td>
    <code>(req, res)</code>
   </td>
   <td>
    String
   </td>
  </tr>
</table>

Optional.

A function that takes [Requests](http://docs.python-requests.org/en/master/api/) request and response objects, and returns a string that corresponds to the session token for this event. 

Similar to [user IDs](#identify_user_outgoing), 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`
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Default
   </th>
  </tr>
  <tr>
   <td>
    Boolean
   </td>
   <td>
    <code>True</code>
   </td>
  </tr>
</table>

Optional.

Set to `False` to remove logging request and response body.

### `SKIP_OUTGOING`
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Parameters
   </th>
   <th scope="col">
    Return type
   </th>
  </tr>
  <tr>
   <td>
    Function
   </td>
   <td>
    <code>(req, res)</code>
   </td>
   <td>
    Boolean
   </td>
  </tr>
</table>

Optional.

A function that takes a [Requests](http://docs.python-requests.org/en/master/api/) request and response objects,
and returns `True` if you want to skip this particular event.

### `MASK_EVENT_MODEL`
<table>
  <tr>
   <th scope="col">
    Data type
   </th>
   <th scope="col">
    Parameters
   </th>
   <th scope="col">
    Return type
   </th>
  </tr>
  <tr>
   <td>
    Function
   </td>
   <td>
    <code>(EventModel)</code>
   </td>
   <td>
    <code>EventModel</code>
   </td>
  </tr>
</table>

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](https://www.moesif.com/docs/api?python).

## Examples

An example Moesif integration is [available on GitHub](https://github.com/Moesif/moesif-python-outgoing-example).

## How to Get Help
If you face any issues, try the [troubheshooting guidelines](#troubleshoot). For further assistance, reach out to our [support team](mailto:support@moesif.com).

## Explore Other Integrations

Explore other integration options from Moesif:

- [Server integration options documentation](https://www.moesif.com/docs/server-integration//)
- [Client integration options documentation](https://www.moesif.com/docs/client-integration/)

[ico-built-for]: https://img.shields.io/badge/built%20for-python%20requests-blue.svg
[ico-version]: https://img.shields.io/pypi/v/moesifpythonrequest.svg
[ico-language]: https://img.shields.io/pypi/pyversions/moesifpythonrequest.svg
[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg
[ico-source]: https://img.shields.io/github/last-commit/moesif/moesifpythonrequest.svg?style=social

[link-built-for]: http://docs.python-requests.org/en/master/
[link-package]: https://pypi.python.org/pypi/moesifpythonrequest
[link-language]: https://pypi.python.org/pypi/moesifpythonrequest
[link-license]: https://raw.githubusercontent.com/Moesif/moesifpythonrequest/master/LICENSE
[link-source]: https://github.com/Moesif/moesifpythonrequest

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.moesif.com/docs",
    "name": "moesifpythonrequest",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "moesif python request monkey patch",
    "author": "Moesif, Inc",
    "author_email": "keyur@moesif.com",
    "download_url": "https://files.pythonhosted.org/packages/33/c5/459b4f7633f5bf9b3b22cf5fd554d3477d064cdfa4f1ec2e4480494ad8c7/moesifpythonrequest-0.3.4.tar.gz",
    "platform": null,
    "description": "# Moesif for Python Requests\nby [Moesif](https://moesif.com), the [API analytics](https://www.moesif.com/features/api-analytics) and [API monetization](https://www.moesif.com/solutions/metered-api-billing) platform.\n\n[![Built For][ico-built-for]][link-built-for]\n[![Latest Version][ico-version]][link-package]\n[![Language Versions][ico-language]][link-language]\n[![Software License][ico-license]][link-license]\n[![Source Code][ico-source]][link-source]\n\nIt's an interceptor for Python Requests library that captures outgoing API calls and sends to [Moesif](https://www.moesif.com) for API analytics and monitoring.\n\n> If you're new to Moesif, see [our Getting Started](https://www.moesif.com/docs/) resources to quickly get up and running.\n\n> If you are using Moesif's API monitoring SDKs like [Moesif Django](https://github.com/Moesif/moesifdjango) or [Moesif WSGI](https://github.com/moesif/moesifwsgi) to log incoming API calls, this library is already included.\n\n## Prerequisites\nBefore using Moesif for Python Requests, make sure you have the following:\n\n- [An active Moesif account](https://moesif.com/wrap)\n- [A Moesif Application ID](#get-your-moesif-application-id)\n\n### Get Your Moesif Application ID\nAfter you log into [Moesif Portal](https://www.moesif.com/wrap), 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:\n\n1. Select the account icon to bring up the settings menu.\n2. Select **Installation** or **API Keys**.\n3. Copy your Moesif Application ID from the **Collector Application ID** field.\n<img class=\"lazyload blur-up\" src=\"images/app_id.png\" width=\"700\" alt=\"Accessing the settings menu in Moesif Portal\">\n\n## Install\nInstall with pip:\n\n```shell\npip install moesifpythonrequest\n```\n\n## Configure\nSee the available [configuration options](#configuration-options) to learn how to configure `moesifpythonrequest` for your use case.\n\n## How to Use\n\nImport the Moesif library and call the `start_capture_outgoing` method.\nMoesif will start logging all API calls made from the Requests library.\n\n```python\nfrom moesifpythonrequest.start_capture.start_capture import StartCapture\nimport requests\n\nmoesif_settings = {\n    'APPLICATION_ID': 'YOUR_MOESIF_APPLICATION_ID'\n}\n\ndef main():\n    # Outgoing API call to third party like Github / Stripe or to your own dependencies\n    response = requests.get(\"http://httpbin.org/uuid\")\n    print(response.json())\n\nStartCapture().start_capture_outgoing(moesif_settings)\nmain()\n```\n\nReplace *`YOUR_MOESIF_APPLICATION_ID`* with [your Moesif Application ID](#get-your-moesif-application-id).\n\n## Troubleshoot\nFor a general troubleshooting guide that can help you solve common problems, see [Server Troubleshooting Guide](https://www.moesif.com/docs/troubleshooting/server-troubleshooting-guide/).\n\nOther troubleshooting supports:\n\n- [FAQ](https://www.moesif.com/docs/faq/)\n- [Moesif support email](mailto:support@moesif.com)\n\n## Repository Structure\n\n```\n.\n\u251c\u2500\u2500 images/\n\u251c\u2500\u2500 LICENSE\n\u251c\u2500\u2500 MANIFEST.in\n\u251c\u2500\u2500 moesifpythonrequest/\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 register.py\n\u251c\u2500\u2500 requirements.txt\n\u251c\u2500\u2500 setup.cfg\n\u2514\u2500\u2500 setup.py\n```\n\n## Configuration options\nThe 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](https://github.com/Moesif/moesif-python-outgoing-example/blob/master/main.py#L31) for better understanding.\n\n### `APPLICATION_ID` (Required)\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    String\n   </td>\n  </tr>\n</table>\n\nA string that [identifies your application in Moesif](#get-your-moesif-application-id).\n\n### `GET_METADATA_OUTGOING`\ntable>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Parameters\n   </th>\n   <th scope=\"col\">\n    Return type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Function\n   </td>\n   <td>\n    <code>(req, res)</code>\n   </td>\n   <td>\n    Dictionary\n   </td>\n  </tr>\n</table>\n\nOptional.\n\nA function that enables you to return custom metadata associated with the logged API calls.\n\nTakes in the [Requests](http://docs.python-requests.org/en/master/api/) request and response objects as arguments. \n\nWe recommend that you implement a function that\nreturns 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.\n\n### `IDENTIFY_USER_OUTGOING`\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Parameters\n   </th>\n   <th scope=\"col\">\n    Return type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Function\n   </td>\n   <td>\n    <code>(req, res)</code>\n   </td>\n   <td>\n    String\n   </td>\n  </tr>\n</table>\n\nOptional, but highly recommended.\n\nA function that takes [Requests](http://docs.python-requests.org/en/master/api/) request and response objects, and returns a string that represents the user ID used by your system. \n\nWhile Moesif tries to identify users automatically, different frameworks and your implementation might vary. So we highly recommend that you accurately provide a \nuser ID using this function.\n\n### `IDENTIFY_COMPANY_OUTGOING`\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Parameters\n   </th>\n   <th scope=\"col\">\n    Return type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Function\n   </td>\n   <td>\n    <code>(req, res)</code>\n   </td>\n   <td>\n    String\n   </td>\n  </tr>\n</table>\n\nOptional.\n\nA function that takes [Requests](http://docs.python-requests.org/en/master/api/) request and response objects and returns a string that represents the company ID for this event.\n\n\n### `GET_SESSION_TOKEN_OUTGOING`\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Parameters\n   </th>\n   <th scope=\"col\">\n    Return type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Function\n   </td>\n   <td>\n    <code>(req, res)</code>\n   </td>\n   <td>\n    String\n   </td>\n  </tr>\n</table>\n\nOptional.\n\nA function that takes [Requests](http://docs.python-requests.org/en/master/api/) request and response objects, and returns a string that corresponds to the session token for this event. \n\nSimilar to [user IDs](#identify_user_outgoing), 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.\n\n### `LOG_BODY_OUTGOING`\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Default\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Boolean\n   </td>\n   <td>\n    <code>True</code>\n   </td>\n  </tr>\n</table>\n\nOptional.\n\nSet to `False` to remove logging request and response body.\n\n### `SKIP_OUTGOING`\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Parameters\n   </th>\n   <th scope=\"col\">\n    Return type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Function\n   </td>\n   <td>\n    <code>(req, res)</code>\n   </td>\n   <td>\n    Boolean\n   </td>\n  </tr>\n</table>\n\nOptional.\n\nA function that takes a [Requests](http://docs.python-requests.org/en/master/api/) request and response objects,\nand returns `True` if you want to skip this particular event.\n\n### `MASK_EVENT_MODEL`\n<table>\n  <tr>\n   <th scope=\"col\">\n    Data type\n   </th>\n   <th scope=\"col\">\n    Parameters\n   </th>\n   <th scope=\"col\">\n    Return type\n   </th>\n  </tr>\n  <tr>\n   <td>\n    Function\n   </td>\n   <td>\n    <code>(EventModel)</code>\n   </td>\n   <td>\n    <code>EventModel</code>\n   </td>\n  </tr>\n</table>\n\nOptional.\n\nA function that takes the final Moesif event model and returns an `EventModel` object with desired data removed.\n\nFor more information about Moesif event model, see [Moesif Python API documentation](https://www.moesif.com/docs/api?python).\n\n## Examples\n\nAn example Moesif integration is [available on GitHub](https://github.com/Moesif/moesif-python-outgoing-example).\n\n## How to Get Help\nIf you face any issues, try the [troubheshooting guidelines](#troubleshoot). For further assistance, reach out to our [support team](mailto:support@moesif.com).\n\n## Explore Other Integrations\n\nExplore other integration options from Moesif:\n\n- [Server integration options documentation](https://www.moesif.com/docs/server-integration//)\n- [Client integration options documentation](https://www.moesif.com/docs/client-integration/)\n\n[ico-built-for]: https://img.shields.io/badge/built%20for-python%20requests-blue.svg\n[ico-version]: https://img.shields.io/pypi/v/moesifpythonrequest.svg\n[ico-language]: https://img.shields.io/pypi/pyversions/moesifpythonrequest.svg\n[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg\n[ico-source]: https://img.shields.io/github/last-commit/moesif/moesifpythonrequest.svg?style=social\n\n[link-built-for]: http://docs.python-requests.org/en/master/\n[link-package]: https://pypi.python.org/pypi/moesifpythonrequest\n[link-language]: https://pypi.python.org/pypi/moesifpythonrequest\n[link-license]: https://raw.githubusercontent.com/Moesif/moesifpythonrequest/master/LICENSE\n[link-source]: https://github.com/Moesif/moesifpythonrequest\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Moesif Python request",
    "version": "0.3.4",
    "project_urls": {
        "Homepage": "https://www.moesif.com/docs"
    },
    "split_keywords": [
        "moesif",
        "python",
        "request",
        "monkey",
        "patch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9970e286c36ac87e4ed3266ce30368bde9b3508424563609e17c3737b23dc7e",
                "md5": "6a6fdb34024e15d07d91f64181963ec3",
                "sha256": "6dea530b558d62abbe6ca9f1789f4ce57c47b3b6a166df739d07851006b03692"
            },
            "downloads": -1,
            "filename": "moesifpythonrequest-0.3.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a6fdb34024e15d07d91f64181963ec3",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 18882,
            "upload_time": "2024-10-29T21:13:31",
            "upload_time_iso_8601": "2024-10-29T21:13:31.327793Z",
            "url": "https://files.pythonhosted.org/packages/a9/97/0e286c36ac87e4ed3266ce30368bde9b3508424563609e17c3737b23dc7e/moesifpythonrequest-0.3.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33c5459b4f7633f5bf9b3b22cf5fd554d3477d064cdfa4f1ec2e4480494ad8c7",
                "md5": "3c50545732262f5bd51e8325d57fbbf0",
                "sha256": "89d39acc9ae65b80e3f895bd213cec8778469e86866b2ed6929b1e502cf8f85b"
            },
            "downloads": -1,
            "filename": "moesifpythonrequest-0.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "3c50545732262f5bd51e8325d57fbbf0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19254,
            "upload_time": "2024-10-29T21:13:32",
            "upload_time_iso_8601": "2024-10-29T21:13:32.672779Z",
            "url": "https://files.pythonhosted.org/packages/33/c5/459b4f7633f5bf9b3b22cf5fd554d3477d064cdfa4f1ec2e4480494ad8c7/moesifpythonrequest-0.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-29 21:13:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "moesifpythonrequest"
}
        
Elapsed time: 3.38252s