Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimon committed Nov 23, 2023
1 parent 54cc5ac commit 850b954
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
64 changes: 42 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p align="center"><b>Your refreshingly simple REST API companion.</b></p>

<p align="center"><i>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.</i></p>
<p align="center"><i>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.</i></p>

<p align="center">🔗 <b><a href="https://apitally.io" target="_blank">apitally.io</a></b></p>

Expand All @@ -22,39 +22,49 @@
[![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)
- [Flask](https://docs.apitally.io/frameworks/flask)
- [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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions apitally/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 850b954

Please sign in to comment.