Skip to main content

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")

Every request uses a default timeout of 10 seconds. Override it for all requests by passing timeout (in seconds):

client = bunnynet.BunnyClient("your-api-token", timeout=30)

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

Release files for bunnynet 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bunnynet 0.5.0
File Size Uploaded
bunnynet-0.5.0.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bunnynet 0.5.0
File Interpreter ABI Platform
bunnynet-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.5 kB

Release files / bunnynet-0.5.0.tar.gz

Download URL bunnynet-0.5.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
822f275dad2e6eb353a3de034add50dce1bbf920f25a178533800a8b041c655e
BLAKE2b-256 checksum
How to use checksums
5c8c17ae7d00353d82e04d7af5d30b43ffa389057f70f28934a872b7bf01af23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.13.14 Windows/11

Release files / bunnynet-0.5.0-py3-none-any.whl

Download URL bunnynet-0.5.0-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55c92c86466b692aeca78413059590cfc56b8bb3376727457abdfa0427201058
BLAKE2b-256 checksum
How to use checksums
11290b6adf9c41107ddb2fd5baad15d8529169a6aa05747b4e27cb14056f687b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.13.14 Windows/11

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page