From 850b954dbabb23afd35f35e0efc55e2f8de39972 Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Thu, 23 Nov 2023 13:52:12 +1000 Subject: [PATCH] Minor tweaks --- README.md | 64 +++++++++++++++++++++++++++-------------- apitally/client/base.py | 4 +-- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 7092084..b2789fb 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

Your refreshingly simple REST API companion.

-

Apitally offers busy engineering teams a simple and affordable API monitoring and API key management solution that is easy to set up and use with new and existing API projects.

+

Apitally is a simple and affordable API monitoring and API key management solution with a focus on data privacy. It is easy to set up and use for new and existing API projects using Python or Node.js.

🔗 apitally.io

@@ -22,7 +22,8 @@ [![Codecov](https://codecov.io/gh/apitally/python-client/graph/badge.svg?token=UNLYBY4Y3V)](https://codecov.io/gh/apitally/python-client) [![PyPI](https://img.shields.io/pypi/v/apitally?logo=pypi&logoColor=white&color=%23006dad)](https://pypi.org/project/apitally/) -This client library for Apitally currently supports the following Python web frameworks: +This client library for Apitally currently supports the following Python web +frameworks: - [FastAPI](https://docs.apitally.io/frameworks/fastapi) - [Starlette](https://docs.apitally.io/frameworks/starlette) @@ -30,31 +31,40 @@ This client library for Apitally currently supports the following Python web fra - [Django Ninja](https://docs.apitally.io/frameworks/django-ninja) - [Django REST Framework](https://docs.apitally.io/frameworks/django-rest-framework) -Learn more about Apitally on our 🌎 [website](https://apitally.io) or check out the 📚 [documentation](https://docs.apitally.io). +Learn more about Apitally on our 🌎 [website](https://apitally.io) or check out +the 📚 [documentation](https://docs.apitally.io). ## Key features -- Middleware for different frameworks to capture metadata about API endpoints, requests and responses (no sensitive data is captured) -- Non-blocking clients that aggregate and send captured data to Apitally and optionally synchronize API key hashes in 1 minute intervals -- Functions to easily secure endpoints with API key authentication and permission checks +- Middleware for different frameworks to capture metadata about API endpoints, + requests and responses (no sensitive data is captured) +- Non-blocking clients that aggregate and send captured data to Apitally and + optionally synchronize API key hashes in 1 minute intervals +- Functions to easily secure endpoints with API key authentication and + permission checks ## Install -Use `pip` to install and provide your framework of choice as an extra, for example: +Use `pip` to install and provide your framework of choice as an extra, for +example: ```bash pip install apitally[fastapi] ``` -The available extras are: `fastapi`, `starlette`, `flask`, `django_ninja` and `django_rest_framework`. +The available extras are: `fastapi`, `starlette`, `flask`, `django_ninja` and +`django_rest_framework`. ## Usage -Our [setup guides](https://docs.apitally.io/quickstart) include all the details you need to get started. +Our [setup guides](https://docs.apitally.io/quickstart) include all the details +you need to get started. ### FastAPI -This is an example of how to add the Apitally middleware to a FastAPI application. For further instructions, see our [setup guide for FastAPI](https://docs.apitally.io/frameworks/fastapi). +This is an example of how to add the Apitally middleware to a FastAPI +application. For further instructions, see our +[setup guide for FastAPI](https://docs.apitally.io/frameworks/fastapi). ```python from fastapi import FastAPI @@ -64,13 +74,15 @@ app = FastAPI() app.add_middleware( ApitallyMiddleware, client_id="your-client-id", - env="your-env-name", + env="default", # or "dev", "prod" etc. ) ``` ### Starlette -This is an example of how to add the Apitally middleware to a Starlette application. For further instructions, see our [setup guide for Starlette](https://docs.apitally.io/frameworks/starlette). +This is an example of how to add the Apitally middleware to a Starlette +application. For further instructions, see our +[setup guide for Starlette](https://docs.apitally.io/frameworks/starlette). ```python from starlette.applications import Starlette @@ -80,13 +92,15 @@ app = Starlette(routes=[...]) app.add_middleware( ApitallyMiddleware, client_id="your-client-id", - env="your-env-name", + env="default", # or "dev", "prod" etc. ) ``` ### Flask -This is an example of how to add the Apitally middleware to a Flask application. For further instructions, see our [setup guide for Flask](https://docs.apitally.io/frameworks/flask). +This is an example of how to add the Apitally middleware to a Flask application. +For further instructions, see our +[setup guide for Flask](https://docs.apitally.io/frameworks/flask). ```python from flask import Flask @@ -96,47 +110,53 @@ app = Flask(__name__) app.wsgi_app = ApitallyMiddleware( app, client_id="your-client-id", - env="your-env-name", + env="default", # or "dev", "prod" etc. ) ``` ### Django Ninja -This is an example of how to add the Apitally middleware to a Django Ninja application. For further instructions, see our [setup guide for Django Ninja](https://docs.apitally.io/frameworks/django-ninja). +This is an example of how to add the Apitally middleware to a Django Ninja +application. For further instructions, see our +[setup guide for Django Ninja](https://docs.apitally.io/frameworks/django-ninja). In your Django `settings.py` file: ```python MIDDLEWARE = [ - # Other middlewares first ... "apitally.django_ninja.ApitallyMiddleware", + # Other middleware ... ] APITALLY_MIDDLEWARE = { "client_id": "your-client-id", - "env": "your-env-name", + "env": "default", # or "dev", "prod" etc. } ``` ### Django REST Framework -This is an example of how to add the Apitally middleware to a Django REST Framework application. For further instructions, see our [setup guide for Django REST Framework](https://docs.apitally.io/frameworks/django-rest-framework). +This is an example of how to add the Apitally middleware to a Django REST +Framework application. For further instructions, see our +[setup guide for Django REST Framework](https://docs.apitally.io/frameworks/django-rest-framework). In your Django `settings.py` file: ```python MIDDLEWARE = [ - # Other middlewares first ... "apitally.django_rest_framework.ApitallyMiddleware", + # Other middleware ... ] APITALLY_MIDDLEWARE = { "client_id": "your-client-id", - "env": "your-env-name", + "env": "default", # or "dev", "prod" etc. } ``` ## Getting help -If you need help please [create a new discussion](https://github.com/orgs/apitally/discussions/categories/q-a) on GitHub. +If you need help please +[create a new discussion](https://github.com/orgs/apitally/discussions/categories/q-a) +on GitHub. ## License diff --git a/apitally/client/base.py b/apitally/client/base.py index 9af1f65..7a4dacf 100644 --- a/apitally/client/base.py +++ b/apitally/client/base.py @@ -74,7 +74,7 @@ def __init__( try: self.handle_keys_response(json.loads(key_data), cache=False) except (json.JSONDecodeError, TypeError, KeyError): # pragma: no cover - logger.exception("Failed to load keys from cache") + logger.exception("Failed to load API keys from cache") @classmethod def get_instance(cls: Type[TApitallyClient]) -> TApitallyClient: @@ -285,7 +285,7 @@ def get(self, api_key: str) -> Optional[KeyInfo]: def hash_api_key(self, api_key: str) -> str: if self.salt is None: - raise RuntimeError("Apitally keys not initialized") + raise RuntimeError("Apitally API keys not initialized") return scrypt(api_key.encode(), salt=bytes.fromhex(self.salt), n=256, r=4, p=1, dklen=32).hex() def update(self, keys: Dict[str, Dict[str, Any]]) -> None: