Skip to main content

A Django integration for libSQL / turso database

Project description

Django + LibSQL / Turso

This project integrates Turso/Libsql with Django, allowing you to use Libsql as a database backend for your Django applications.

Installation

To install the package, use pip:

pip install django-libsql

Configuration

To use Libsql as your database backend, update your Django settings as follows:

DATABASES = {
    "default": {
        "ENGINE": "libsql.db.backends.sqlite3",
        "NAME": "libsql://${your-db-name}.turso.io?authToken=${your-auth-token}",
    }
}

Replace ${your-db-name} and ${your-auth-token} with your actual database name and authentication token.

Usage

After configuration, you can use Django's ORM as usual. The Libsql backend will handle the database operations.

Running a Local LibSQL Server

To start a local LibSQL server for development or testing, use the provided script:

./scripts/docker.sh

This script will start a LibSQL server in a Docker container.

Running Django app

You can also clone this repository and run the example Django app:

git clone https://github.com/aaronkazah/django-libsql.git
cd django-libsql
./scripts/docker.sh
python manage.py migrate
python manage.py runserver

Feel free to modify the DATABASES configuration in settings.py to point to your local LibSQL server or turso.io.

Running Tests

To run tests and verify the integration, use the provided script:

./scripts/test.sh

This script performs a self-lifecycle test:

  1. It starts a local LibSQL server using Docker.
  2. Runs the tests against this server.
  3. Destroys the server at the end of the test run.

This process confirms that the integration is working correctly with an actual LibSQL server.

Self-Hosting

If you want to host your own Libsql server, refer to the provided Docker script (./scripts/docker.sh). This script includes a working server setup along with key generation.

Known Issues

The current implementation has some limitations due to the lack of support for custom functions in the libsql_client:

  1. Custom Django functions registered via create_function are not supported.
  2. Certain Django ORM features that rely on these custom functions will not work. For example:
    • Date/time operations using F() objects
    • dates() queryset method

For a complete list of unsupported functions, query the pragma_function_list table in your database.

Examples of Unsupported Operations

  1. Date difference annotation:

    Company.objects.annotate(date_diff=F("valid_until") - F("made_at"))
    
  2. Date truncation in queryset:

    Company.objects.dates("last_updated", "year")
    

These operations will raise django.db.utils.OperationalError due to missing functions.

License

This project is distributed under the MIT license.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.

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_libsql-0.1.3.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

django_libsql-0.1.3-py3-none-any.whl (50.2 kB view details)

Uploaded Python 3

File details

Details for the file django_libsql-0.1.3.tar.gz.

File metadata

  • Download URL: django_libsql-0.1.3.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for django_libsql-0.1.3.tar.gz
Algorithm Hash digest
SHA256 aae4cf84829c162462e3c4edb74ed3747465cab0295e11aecc6aabb0f5c6bbba
MD5 21c804d8d3526ea18d7a14e7d0593b07
BLAKE2b-256 752ca6c61641fa1ea5d0ba6f6e3a5e0d54909aebc24b667e844db29162e6c447

See more details on using hashes here.

File details

Details for the file django_libsql-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_libsql-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 50.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for django_libsql-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7eea05228ed87b4388e8056372db4b893086f4faa84fefe14a179c2ba7865bd1
MD5 7e4f40fdb99441bd2a1707e7f94d02c4
BLAKE2b-256 c6ee5e30a9535bdab4752c4d4560a2a83127bf5697866c64fa66fdf09679c16c

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