https://github.com/quantmind/aio-kong
Asynchronous python client for kong
https://github.com/quantmind/aio-kong
Last synced: 25 days ago
JSON representation
Asynchronous python client for kong
- Host: GitHub
- URL: https://github.com/quantmind/aio-kong
- Owner: quantmind
- License: bsd-3-clause
- Created: 2018-05-14T14:47:23.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2026-01-06T00:45:31.000Z (about 1 month ago)
- Last Synced: 2026-01-08T01:36:25.318Z (about 1 month ago)
- Language: Python
- Size: 542 KB
- Stars: 9
- Watchers: 6
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Async Python Client for Kong
[](https://badge.fury.io/py/aio-kong)
[](https://pypi.org/project/aio-kong)
[](https://github.com/quantmind/aio-kong/actions?query=workflow%3Abuild)
[](https://codecov.io/gh/quantmind/aio-kong)
[](https://pypi.org/project/aio-kong/)
Tested with [kong][] v3.8
## Installation
To install the package
```
pip install aio-kong
```
## Testing
To run tests, clone the repository and
```
make install
make test
```
:warning: If you don't have Kong or postgres running locally, run the services first
```bash
make services
```
test certificates were generated using the command
```
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -subj '/CN=localhost'
```
## Client
The client can be imported via
```python
from kong.client import Kong
```
In a coroutine:
```python
async with Kong() as cli:
services = await cli.services.get_list()
print(json.dumps([s.data for s in services], indent=2))
```
By default the url is obtained from the "KONG_ADMIN_URL" environment variable which defaults to http://127.0.0.1:8001.
The client has handlers for all Kong objects
- [cli.services](./kong/services.py) CRUD operations on services
- [cli.routes](./kong/routes.py) CRUD operations on routes
- [cli.plugins](./kong/plugins.py) CRUD operations on plugins
- [cli.consumers](./kong/consumers.py) CRUD operations on consumers
- [cli.certificates](./kong/certificates.py) CRUD operations on TLS certificates
- [cli.snis](./kong/snis.py) CRUD operations on SNIs
- `cli.acls` To list all ACLs
### Apply a configuration
The client allow to apply a configuration object to kong:
```python
await cli.apply_json(config)
```
## Command line tool
The library can install the `kongfig` command line tool for uploading kong configuration files.
For the command line tool to work, you need to install the package as:
```bash
pip install aio-kong[cli]
```
and to run the cli tool, you can use the following command:
```
kongfig --help
```
## Environment variables
The client uses the following environment variables:
* `KONG_ADMIN_URL`: The URL of the Kong admin API. Defaults to `http://127.0.0.1:8001`.
* `KONG_ADMIN_SSL`: Whether to use SSL validation for the Kong admin API. Defaults to `true`.
[kong]: https://github.com/Kong/kong