Skip to content

Operations

List resources

Use fetch_all to iterate over all resources. It returns an async generator:

python
import asyncio
from cacholong_sdk import connection, DnsZone

async def main():
    async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
        ctrl = DnsZone(api)
        async for zone in ctrl.fetch_all():
            print(zone["domain"])

asyncio.run(main())

Fetch a single resource

Use fetch to retrieve a resource by its UUID:

python
import asyncio
from cacholong_sdk import connection, DnsZone

async def main():
    async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
        ctrl = DnsZone(api)
        zone = await ctrl.fetch("ZONE-UUID")
        print(zone["domain"])

asyncio.run(main())

Create a resource

Call ctrl.create() to get a blank model, set attributes, then call await ctrl.store(model):

python
import asyncio
from cacholong_sdk import connection, DnsZone, ResourceTuple

async def main():
    async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
        ctrl = DnsZone(api)
        zone = ctrl.create()
        zone["domain"] = "example.com"
        zone["account"] = ResourceTuple("ACCOUNT-UUID", "accounts")
        await ctrl.store(zone)

asyncio.run(main())

Resources with variant create

Some controllers (DnsRecord, Address) require a specific relationship to be set before calling store() and expose store_with_* helpers. See Custom Actions for details.

Update a resource

Fetch the resource, mutate the attributes you want to change, then call await ctrl.update(model):

python
import asyncio
from cacholong_sdk import connection, DnsZone

async def main():
    async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
        ctrl = DnsZone(api)
        zone = await ctrl.fetch("ZONE-UUID")
        zone["dnssec"] = True
        await ctrl.update(zone)

asyncio.run(main())

Delete a resource

Pass the UUID directly to destroy — no model fetch is required:

python
import asyncio
from cacholong_sdk import connection, DnsZone

async def main():
    async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
        ctrl = DnsZone(api)
        await ctrl.destroy("ZONE-UUID")

asyncio.run(main())