A client for the bunny.net APIs
Project description
bunnynet
A Python client for the bunny.net APIs.
Installation
pip install bunnynet
Usage
Create a client with your bunny.net account API token:
import bunnynet
client = bunnynet.BunnyClient("your-api-token")
Storage zones
# Iterate over every storage zone
for zone in client.storage_zones.get_all():
print(zone.name)
# Look one up by id or name (returns None if it doesn't exist)
zone = client.storage_zones.get_by_name("my-zone")
# Upload, read and delete files
client.storage_zones.upload_text_file(
storage_zone=zone,
contents="Hello World",
path="some/path",
file_name="hello.txt",
)
text = client.storage_zones.get_text_file(storage_zone=zone, path="some/path", file_name="hello.txt")
client.storage_zones.delete_file(storage_zone=zone, path="some/path", file_name="hello.txt")
Pull zones
for zone in client.pull_zones.get_all():
print(zone.name)
Provisioning a pull zone
The pull zone client can also create and configure zones:
pull_zones = client.get_pull_zone_client()
zone = pull_zones.get_by_name("my-zone") or pull_zones.create(
name="my-zone",
origin_url="https://origin.example.com",
)
# Apply settings using bunny.net's PascalCase field names. -1 on
# CacheControlMaxAgeOverride tells bunny.net to respect the origin's
# Cache-Control headers.
pull_zones.update(zone.identifier, {
"IgnoreQueryStrings": False,
"EnableQueryStringOrdering": True,
"CacheControlMaxAgeOverride": -1,
})
# Attach a custom hostname, issue a free Let's Encrypt certificate and force
# HTTPS. The hostname's CNAME must resolve to <zone>.b-cdn.net before the
# certificate can be issued.
pull_zones.add_hostname(zone.identifier, "cdn.example.com")
pull_zones.load_free_certificate("cdn.example.com")
pull_zones.set_force_ssl(zone.identifier, "cdn.example.com", force=True)
Signed URLs
import datetime
signed = client.sign_url(
"https://example.b-cdn.net/foo/bar/file.png",
key="your-token-authentication-key",
expiration=datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1),
)
Purging the cache
client.purge_url("https://example.b-cdn.net/foo/bar/file.png")
Development
Install dependencies and run the tests with Poetry:
poetry install
poetry run pytest
The integration tests in tests/test_bunnynet.py require a BUNNY_TOKEN
environment variable and are skipped when it is not set. The offline unit tests
in tests/test_unit.py always run.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bunnynet-0.4.0.tar.gz.
File metadata
- Download URL: bunnynet-0.4.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.13.14 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2cf4b3c18116850f4c496e41bae049ba4d6b8651a1ffec6503aca1e6ddfa03f
|
|
| MD5 |
52d7b3f727253f3bc7ce7967569e08cf
|
|
| BLAKE2b-256 |
8f0c6ecfb0b6f1222aa881fd2bc61c1291e857288316a6404fc1978e42822cb6
|
File details
Details for the file bunnynet-0.4.0-py3-none-any.whl.
File metadata
- Download URL: bunnynet-0.4.0-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.13.14 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9128604323bb1076a7921c0f3b739ed25469acf9d0147f4b9bde558170965b4e
|
|
| MD5 |
ccb003ad719498b196f7d29a62996e1b
|
|
| BLAKE2b-256 |
b045c6a816de461ab66757c8b66a14be6acbed3708abdad9032da12bd389f5e6
|