Python
SDK for bunny.net 🐰
Installation
pip install bunny-sdk
Prerequisites
- Please read the authentication guide to learn more about where to find your
AccessKey
and whichAccessKey
should be used for each client. - Please read the limitations guide to learn more about known limitations and bugs, such as
nullable
andoptional
typing. - Please read the supported endpoints guide to learn more about which endpoints are supported.
Quickstart
Create the client
from os import environfrom bunny_sdk import create_bunny_api_clientclient = create_bunny_api_client(access_key=environ.get("BUNNY_ACCESS_KEY", ""))
Call a simple endpoint
fetch countries
from os import environimport asyncio from bunny_sdk import create_bunny_api_clientclient = create_bunny_api_client(access_key=environ.get("BUNNY_ACCESS_KEY", ""))async def main(): countries = await client.country.get()asyncio.run(main())
log countries
from os import environimport asynciofrom bunny_sdk import create_bunny_api_clientclient = create_bunny_api_client(access_key=environ.get("BUNNY_ACCESS_KEY", ""))async def main(): countries = await client.country.get() assert countries, "countries is None" for i, country in enumerate(countries): assert country.name, "country.name is None" print(f"{i}: {country.name}")asyncio.run(main())
Call a complex endpoint
The List Storage Zones endpoint is a more complex example that has required parameters.
fetch storage zones
from os import environimport asyncio from bunny_sdk import create_bunny_api_clientfrom bunny_sdk.bunny_api_client.storagezone.storagezone_request_builder import ( StoragezoneRequestBuilder,)client = create_bunny_api_client(access_key=environ.get("BUNNY_ACCESS_KEY", ""))async def main(): storageZonesResponse = await client.storagezone.get( request_configuration=StoragezoneRequestBuilder.StoragezoneRequestBuilderGetRequestConfiguration( query_parameters=StoragezoneRequestBuilder.StoragezoneRequestBuilderGetQueryParameters( include_deleted=True, page=1, per_page=1000 ) ) )asyncio.run(main())
log storage zones
from os import environimport asynciofrom bunny_sdk import create_bunny_api_clientfrom bunny_sdk.bunny_api_client.storagezone.storagezone_request_builder import ( StoragezoneRequestBuilder,)client = create_bunny_api_client(access_key=environ.get("BUNNY_ACCESS_KEY", ""))async def main(): storageZonesResponse = await client.storagezone.get( request_configuration=StoragezoneRequestBuilder.StoragezoneRequestBuilderGetRequestConfiguration( query_parameters=StoragezoneRequestBuilder.StoragezoneRequestBuilderGetQueryParameters( include_deleted=True, page=1, per_page=1000 ) ) ) assert storageZonesResponse, "storageZonesResponse is None" storageZones = storageZonesResponse.items assert storageZones, "storageZones is None" for i, storageZone in enumerate(storageZones): assert storageZone.name, "storageZone.name is None" print(f"{i}: {storageZone.name}")asyncio.run(main())
All required parameters from the documentation are also required in the Bunny SDK. In this example, the required parameters are:
include_deleted
page
per_page
Despite the documentation setting the default page
parameter to 0
, the default value fails the validation, where the minimum page is 1
.
If you receive a 400 Bad Request
error, please double-check your parameters.
Python classes
Most model and enum classes are found in:
bunny_sdk.<client>.<group>.<builder>
.bunny_sdk.<client>.models.<group>
.
from bunny_sdk.bunny_api_client.storagezone.storagezone_request_builder import ( StoragezoneRequestBuilder,)from bunny_sdk.bunny_api_client.models.storage_zone import storage_zone, edge_replication_regions