Skip to main content

Django backend for Cloudflare D1 and Durable Objects

Project description

django-cf

Django database engine for Cloudflare D1 and Durable Objects

Installation

pip install django-cf

Using with D1

The D1 engine uses the HTTP api directly from Cloudflare, meaning you only need to create a new D1 database, then create an API token with D1 read permission, and you are good to go!

But using an HTTP endpoint for executing queries one by one is very slow, and currently there is no way to accelerate it, until a websocket endpoint is available.

The HTTP api doesn't support transactions, meaning all execute queries are final and rollbacks are not available.

DATABASES = {
    'default': {
        'ENGINE': 'django_d1',
        'CLOUDFLARE_DATABASE_ID': '<database_id>',
        'CLOUDFLARE_ACCOUNT_ID': '<account_id>',
        'CLOUDFLARE_TOKEN': '<token>',
    }
}

The Cloudflare token requires D1 Edit permissions.

A simple tutorial is available here for you to read.

Using with Durable Objects

The DO engine, requires you to deploy workers-dbms on your cloudflare account. This engine uses a websocket endpoint to keep the connection alive, meaning sql queries are executed way faster.

workers-dbms have an experimental transaction support, everything should be working out of the box, but you should keep an eye out for weird issues and report them back.

DATABASES = {
    'default': {
        'ENGINE': 'django_dbms',
        'WORKERS_DBMS_ENDPOINT': '<websocket_endpoint>',  # This should start with wss://
        'WORKERS_DBMS_ACCESS_ID': '<access_id>',  # Optional, but highly recommended!
        'WORKERS_DBMS_ACCESS_SECRET': '<access_secret>',  # Optional, but highly recommended!
    }
}

Limitations

When using D1 engine, queries are expected to be slow, and transactions are disabled.

Read all Django limitations for SQLite databases here.

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

django_cf-0.0.12.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cf-0.0.12-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file django_cf-0.0.12.tar.gz.

File metadata

  • Download URL: django_cf-0.0.12.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for django_cf-0.0.12.tar.gz
Algorithm Hash digest
SHA256 92098e3bf6196dc267f5580e6011ca1eaa5596459ba9964b5f7518d9ef35faf4
MD5 50d50e8b6c35967588528e6631361964
BLAKE2b-256 52833369a2eb7dca2d233268d4ff8ad7412edcfb69131fa588f18bcae5efb6b5

See more details on using hashes here.

File details

Details for the file django_cf-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: django_cf-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for django_cf-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 45c7749860c92eea9e7cd28e3ae0d8ec4cfcbea5fc1522745db8512227328521
MD5 63801f315473f409801258d46f2dda93
BLAKE2b-256 db0160e25e0bc356ac1d2a28126214cd6b5cf8d8dc2adc0832a1880ba7ce7f31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page