apitoolkit-django


Nameapitoolkit-django JSON
Version 0.3.0 PyPI version JSON
download
home_page
SummaryAPIToolkit SDK for Django
upload_time2024-03-11 19:30:00
maintainer
docs_urlNone
authorAPIToolkit
requires_python>=3.8
licenseMIT License Copyright (c) 2023 APIToolkit Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords api apitoolkit observability api monitoring
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # API Toolkit Python Django SDK

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

## How to Integrate:

First install the apitoolkit django sdk:
`pip install apitoolkit-django`

Add your APIToolkit API key (APITOOLKIT_KEY) to your django settings:

```python
APITOOLKIT_KEY = "<YOUR_API_KEY>"
```

Then add apitoolkit middleware into the settings middleware list:

```python

MIDDLEWARE = [
    ...,
    'apitoolkit_django.APIToolkit',
    ...,
]

```

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 your application's settings.
Eg:

```python
APITOOLKIT_REDACT_HEADERS = ["Authorization", "Cookie","Content-Length", "Content-Type"]
APITOOLKIT_REDACT_REQ_BODY = ["$.password", "$.credit_card"]
APITOOLKIT_REDACT_RES_BODY = ["$.credentials", "$.social_security_number"]
```

It is important to note that while the `APITOOLKIT_REDACT_HEADERS` config field accepts a list of headers(case insensitive),
the `APITOOLKIT_REDACT_REQ_BODY` and `APITOOLKIT_REDACT_RES_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](https://lzone.de/cheat-sheet/JSONPath)

## Debugging

You can add `APITOOLKIT_DEBUG` to your app settings file and set it to `True` to enable debug logging from the SDK. This will print out logs for each request/response captured by the middleware. APITOOLKIT_DEBUG defaults to `False`.

Eg:

```python

APITOOLKIT_DEBUG = True

```

## Tags and Service versions

You can also add tags and service versions in your requests monitoring by adding them in your `settings.py` file

#### Example

```python
APITOOLKIT_TAGS = ["PROD", "EU"]
APITTOLKIT_SERVICE_VERSION = "2.0.0"
```

# Outgoing Requests

To monitor outgoing HTTP requests from your Django application, you can use the `observe_request` function from the `apitoolkit_django` module. This allows you to capture and send copies of all incoming and outgoing requests to an apitoolkit server for monitoring and analysis.

### Example

```python
from django.http import JsonResponse
from apitoolkit_django import observe_request, report_error


def hello_world(request, name):
    resp = observe_request(request).get(
        "https://jsonplaceholder.typicode.com/todos/2")
    resp.read()
    return JsonResponse({"data": resp.read()})
```

The `observe_request` function wraps an httpx client and you can use it just like you would normally use httpx for any request you need.

# Error Reporting

If you’ve used sentry, or bugsnag, or rollbar, then you’re already familiar with this usecase.
But you can report an error to apitoolkit. A difference, is that errors are always associated with a parent request, and helps you query and associate the errors which occured while serving a given customer request. To request errors to APIToolkit use the `report_error` function from the `apitoolkit_django` module to report an error you can report as many errors you want during a request

### Example

```python
from django.http import JsonResponse
from apitoolkit_django import observe_request, report_error

def hello_world(request, name):
    try:
        resp = observe_request(request).get(
            "https://jsonplaceholder.typicode.com/todos/2")
        resp.read()
        return JsonResponse({"hello": "world"})
    except Exception as e:
        report_error(request, e)
        return JsonResponse({"Error": "Something went wrong"})
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "apitoolkit-django",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "API,APIToolkit,Observability,API Monitoring",
    "author": "APIToolkit",
    "author_email": "Anthony ALaribe <anthonyalaribe@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4d/11/5af27672cab7d305c0d4535458a62091ef12816f18366c1529c77d909058/apitoolkit-django-0.3.0.tar.gz",
    "platform": null,
    "description": "# API Toolkit Python Django SDK\n\nThe API Toolkit django client is an sdk used to integrate django web applications with APIToolkit.\nIt monitors incoming traffic, gathers the requests and sends the request to the apitoolkit servers.\n\n## How to Integrate:\n\nFirst install the apitoolkit django sdk:\n`pip install apitoolkit-django`\n\nAdd your APIToolkit API key (APITOOLKIT_KEY) to your django settings:\n\n```python\nAPITOOLKIT_KEY = \"<YOUR_API_KEY>\"\n```\n\nThen add apitoolkit middleware into the settings middleware list:\n\n```python\n\nMIDDLEWARE = [\n    ...,\n    'apitoolkit_django.APIToolkit',\n    ...,\n]\n\n```\n\nThis will monitor all requests and send them to the APIToolkit's servers.\n\n## Client Redacting fields\n\nWhile it's possible to mark a field as redacted from the apitoolkit dashboard, this client also supports redacting at the client side.\nClient 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.\n\nTo mark fields that should be redacted, add them to your application's settings.\nEg:\n\n```python\nAPITOOLKIT_REDACT_HEADERS = [\"Authorization\", \"Cookie\",\"Content-Length\", \"Content-Type\"]\nAPITOOLKIT_REDACT_REQ_BODY = [\"$.password\", \"$.credit_card\"]\nAPITOOLKIT_REDACT_RES_BODY = [\"$.credentials\", \"$.social_security_number\"]\n```\n\nIt is important to note that while the `APITOOLKIT_REDACT_HEADERS` config field accepts a list of headers(case insensitive),\nthe `APITOOLKIT_REDACT_REQ_BODY` and `APITOOLKIT_REDACT_RES_BODY` expect a list of JSONPath strings as arguments.\n\nThe choice of JSONPath was selected to allow you have great flexibility in descibing which fields within your responses are sensitive.\nAlso note that these list of items to be redacted will be aplied to all endpoint requests and responses on your server.\nTo learn more about jsonpath to help form your queries, please take a look at this cheatsheet:\n[https://lzone.de/cheat-sheet/JSONPath](https://lzone.de/cheat-sheet/JSONPath)\n\n## Debugging\n\nYou can add `APITOOLKIT_DEBUG` to your app settings file and set it to `True` to enable debug logging from the SDK. This will print out logs for each request/response captured by the middleware. APITOOLKIT_DEBUG defaults to `False`.\n\nEg:\n\n```python\n\nAPITOOLKIT_DEBUG = True\n\n```\n\n## Tags and Service versions\n\nYou can also add tags and service versions in your requests monitoring by adding them in your `settings.py` file\n\n#### Example\n\n```python\nAPITOOLKIT_TAGS = [\"PROD\", \"EU\"]\nAPITTOLKIT_SERVICE_VERSION = \"2.0.0\"\n```\n\n# Outgoing Requests\n\nTo monitor outgoing HTTP requests from your Django application, you can use the `observe_request` function from the `apitoolkit_django` module. This allows you to capture and send copies of all incoming and outgoing requests to an apitoolkit server for monitoring and analysis.\n\n### Example\n\n```python\nfrom django.http import JsonResponse\nfrom apitoolkit_django import observe_request, report_error\n\n\ndef hello_world(request, name):\n    resp = observe_request(request).get(\n        \"https://jsonplaceholder.typicode.com/todos/2\")\n    resp.read()\n    return JsonResponse({\"data\": resp.read()})\n```\n\nThe `observe_request` function wraps an httpx client and you can use it just like you would normally use httpx for any request you need.\n\n# Error Reporting\n\nIf you\u2019ve used sentry, or bugsnag, or rollbar, then you\u2019re already familiar with this usecase.\nBut you can report an error to apitoolkit. A difference, is that errors are always associated with a parent request, and helps you query and associate the errors which occured while serving a given customer request. To request errors to APIToolkit use the `report_error` function from the `apitoolkit_django` module to report an error you can report as many errors you want during a request\n\n### Example\n\n```python\nfrom django.http import JsonResponse\nfrom apitoolkit_django import observe_request, report_error\n\ndef hello_world(request, name):\n    try:\n        resp = observe_request(request).get(\n            \"https://jsonplaceholder.typicode.com/todos/2\")\n        resp.read()\n        return JsonResponse({\"hello\": \"world\"})\n    except Exception as e:\n        report_error(request, e)\n        return JsonResponse({\"Error\": \"Something went wrong\"})\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 APIToolkit  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "APIToolkit SDK for Django",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/apitoolkit/apitoolkit-django"
    },
    "split_keywords": [
        "api",
        "apitoolkit",
        "observability",
        "api monitoring"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d115af27672cab7d305c0d4535458a62091ef12816f18366c1529c77d909058",
                "md5": "6ef95f0da7744a4c6d9c9c88ee107ecb",
                "sha256": "e5c15e86cbfa1063eb0dcd1678ce8e85ae710066c45c7520db4b4c741ae58fbf"
            },
            "downloads": -1,
            "filename": "apitoolkit-django-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6ef95f0da7744a4c6d9c9c88ee107ecb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6033,
            "upload_time": "2024-03-11T19:30:00",
            "upload_time_iso_8601": "2024-03-11T19:30:00.147159Z",
            "url": "https://files.pythonhosted.org/packages/4d/11/5af27672cab7d305c0d4535458a62091ef12816f18366c1529c77d909058/apitoolkit-django-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-11 19:30:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "apitoolkit",
    "github_project": "apitoolkit-django",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "apitoolkit-django"
}
        
Elapsed time: 0.20828s