Skip to main content

Supabase integration for pydantic

Project description

Supadantic

PyPI - Downloads GitHub License versions pypi

Supadantic is a small Python library that allows you to manage Supabase tables through Pydantic models. It is very convenient to use in projects based on FastAPI, Flask, and so on.

Important information

Supadantic may not have backward compatibility until version 0.1.0. This is because the library is still experimental and is being used in several of my other projects, where requirements are still being finalized.

Help

See documentation for more details.

Installation

Install using pip install -U supadantic.

Also, you need to add SUPABASE_URL and SUPABASE_KEY to your env variables.

A Simple example

from supadantic.models import BaseSBModel


class User(BaseSBModel):
    # id field already defined in BaseSBModel class
    name: str = 'John Doe'
    is_active: bool = True

    # By default table name is class name in snake_case
    # If you want to change it - you should implement _get_table_name method
    @classmethod
    def _get_table_name(cls) -> str:
        return 'db_user'

# Save user
active_user = User(name='John Snow')
active_user.save()

non_active_user = User(is_active=False)
non_active_user.save()

# Get all users
users = User.objects.all()

# Count users
users.count()

# Get first user
users.first()

# Get last user
users.last()

# Filter users
active_users = User.objects.filter(is_active=True)
# Or
active_users = User.objects.exclude(is_active=False)

# Update all active users
active_users.update(is_active=False)

# Delete all non active users
User.objects.exclude(is_active=True).delete()

# Get one user and delete
user = User.objects.get(name='John Doe')
user.delete()

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

supadantic-0.0.7.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

supadantic-0.0.7-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file supadantic-0.0.7.tar.gz.

File metadata

  • Download URL: supadantic-0.0.7.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for supadantic-0.0.7.tar.gz
Algorithm Hash digest
SHA256 fcd92c59b6aff187ae246f14c1ee28d4f5c6674de87949ddf78731510584d68c
MD5 e1a018637f1c0a18c4538af4bd677f6b
BLAKE2b-256 f65cac4cbefbdd83f004d5eadebfcaeb792fa1ba8c15cbb7c6f0692f7a8be2ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for supadantic-0.0.7.tar.gz:

Publisher: release.yml on makridenko/supadantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file supadantic-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: supadantic-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for supadantic-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf33fc9e4cb2e1fc80d7984a50031dc492498b8b68f7cdc518d024cbc87e66a
MD5 793ac115352ebbb3a919eba7ff8fd8b2
BLAKE2b-256 476f8d94cefd867552a29c82432bd3d6205619bc372f377a4c0d9f26d83d24fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for supadantic-0.0.7-py3-none-any.whl:

Publisher: release.yml on makridenko/supadantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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