apitoolkit-fastapi


Nameapitoolkit-fastapi JSON
Version 0.2.0 PyPI version JSON
download
home_page
Summary
upload_time2023-11-09 16:51:33
maintainer
docs_urlNone
authorAPIToolkit
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # API Toolkit Python FastAPI SDK

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

## Design decisions:

- Use the gcp SDK to send real time traffic from REST APIs to the gcp topic

## How to Integrate:

First install the apitoolkit Go sdk:
`pip install apitoolkit-fastapi`

Then add apitoolkit to your app like so (Gin example):

```php
from fastapi import FastAPI
from apitoolkit_fastapi import APIToolkit

app = FastAPI()

# Initialize apitoolkit
apitoolkit = APIToolkit(api_key='<API_KEY goes here>')

app.middleware('http')(apitoolkit.middleware)


@app.get("/")
def read_root():
    return {"Hello": "World"}
```

## 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, simply add them to the apitoolkit config struct.
Eg:

```python
from fastapi import FastAPI
from apitoolkit_fastapi import APIToolkit

app = FastAPI()

# A list of fields to redact from response body
redact_res = ["$.api_key", "$.password"]
# A list of fields to redact from request body
redact_req = ["$.credit-card.cvv", "$.credit-card.name"]
# A list of fields to redact from request and repsonse headers
redact_headers = ["Authorization", "Cookie"]

# Initialize apitoolkit
apitoolkit = APIToolkit(
    api_key="<API_KEY>", debug=True,redact_response_body=redact_res,
    redact_request_body=redact_req,redact_headers=redact_headers
)

app.middleware('http')(apitoolkit.middleware)

@app.get("/")
def read_root():
    return {"Hello": "World"}
```

It is important to note that while the `redact_headers` config field accepts a list of headers(case insensitive),
the `redact_request_body` and `redact_response_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)



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "apitoolkit-fastapi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "APIToolkit",
    "author_email": "hello@apitoolkit.io",
    "download_url": "https://files.pythonhosted.org/packages/84/13/92038c760e390e826d1aaa519ece656049083ca6d80153fc224c739bfd30/apitoolkit_fastapi-0.2.0.tar.gz",
    "platform": null,
    "description": "# API Toolkit Python FastAPI SDK\n\nThe API Toolkit FastAPI client is an sdk used to integrate FastAPI web services with APIToolkit.\nIt monitors incoming traffic, gathers the requests and sends the request to the apitoolkit servers.\n\n## Design decisions:\n\n- Use the gcp SDK to send real time traffic from REST APIs to the gcp topic\n\n## How to Integrate:\n\nFirst install the apitoolkit Go sdk:\n`pip install apitoolkit-fastapi`\n\nThen add apitoolkit to your app like so (Gin example):\n\n```php\nfrom fastapi import FastAPI\nfrom apitoolkit_fastapi import APIToolkit\n\napp = FastAPI()\n\n# Initialize apitoolkit\napitoolkit = APIToolkit(api_key='<API_KEY goes here>')\n\napp.middleware('http')(apitoolkit.middleware)\n\n\n@app.get(\"/\")\ndef read_root():\n    return {\"Hello\": \"World\"}\n```\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, simply add them to the apitoolkit config struct.\nEg:\n\n```python\nfrom fastapi import FastAPI\nfrom apitoolkit_fastapi import APIToolkit\n\napp = FastAPI()\n\n# A list of fields to redact from response body\nredact_res = [\"$.api_key\", \"$.password\"]\n# A list of fields to redact from request body\nredact_req = [\"$.credit-card.cvv\", \"$.credit-card.name\"]\n# A list of fields to redact from request and repsonse headers\nredact_headers = [\"Authorization\", \"Cookie\"]\n\n# Initialize apitoolkit\napitoolkit = APIToolkit(\n    api_key=\"<API_KEY>\", debug=True,redact_response_body=redact_res,\n    redact_request_body=redact_req,redact_headers=redact_headers\n)\n\napp.middleware('http')(apitoolkit.middleware)\n\n@app.get(\"/\")\ndef read_root():\n    return {\"Hello\": \"World\"}\n```\n\nIt is important to note that while the `redact_headers` config field accepts a list of headers(case insensitive),\nthe `redact_request_body` and `redact_response_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\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "0.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "841392038c760e390e826d1aaa519ece656049083ca6d80153fc224c739bfd30",
                "md5": "2b641904ba15fdc020cdb190b71963e0",
                "sha256": "95349a3be8cb464206645aabc67b63565f51f9be5eabdbf1becf2626069d1a79"
            },
            "downloads": -1,
            "filename": "apitoolkit_fastapi-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2b641904ba15fdc020cdb190b71963e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5123,
            "upload_time": "2023-11-09T16:51:33",
            "upload_time_iso_8601": "2023-11-09T16:51:33.782497Z",
            "url": "https://files.pythonhosted.org/packages/84/13/92038c760e390e826d1aaa519ece656049083ca6d80153fc224c739bfd30/apitoolkit_fastapi-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-09 16:51:33",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "apitoolkit-fastapi"
}
        
Elapsed time: 0.14478s