Skip to main content

Djene: Inject a Django Gene Into Your SQLModel

Project description

Djene: Inject a Django Gene Into Your SQLModel

Tired of SQLModel's plain queries? Give your models a dose of Django's expressive querysets with Djene!

Key Features

  • Unleash the Django Within: Filter, order, get, and more using Django's beloved queryset API.
  • SQLModel Superpowers: Keep all the benefits of SQLModel while writing cleaner, chainable queries.
  • Seamless Integration: No genetic engineering required – Djene works with your existing models.
  • Evolve Your Queries: Extend Djene's queryset behavior to adapt to your project's unique DNA.
  • FastAPI Compatibility: Built-in middleware makes integrating with FastAPI a breeze.

Disclaimer: Djene is still in its experimental phase. We welcome your feedback and contributions as we work towards a stable release.

Installation

pip install djene

Usage with FastAPI (Genetic Modification Example)

from fastapi import FastAPI
from sqlmodel import create_engine, Field, SQLModel
from typing import Optional

from djene import DjeneMiddleware, dj

# Database setup (replace with your actual credentials)
engine = create_engine("postgresql+psycopg2://user:password@host/database")

app = FastAPI()
app.add_middleware(DjeneMiddleware, engine=engine)

class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True, index=True)
    name: str
    age: Optional[int] = Field(default=None)

@app.get("/hero/{hero_id}")
def get_hero(hero_id: int):
    hero = dj(Hero).get_or_none(id=hero_id)
    return hero if hero is not None else {"error": "Hero not found"}

Unleash Your Inner Django

# Filtering
heroes = dj(Hero).filter(age__gt=30, name__startswith="S")  # Find strong heroes over 30
heroes = dj(Hero).filter(age__in=[25, 35])                 # Heroes aged 25 or 35
heroes = dj(Hero).filter(name__isnull=True)                # Heroes with no name

# Ordering
heroes = dj(Hero).order_by("-age")                          # Rank heroes by experience (age)

# Retrieving
hero = dj(Hero).get(id=1)                                  # Get a specific hero
first_hero = dj(Hero).first()                              # Get the first hero
all_heroes = dj(Hero).all()                                # Get all heroes

# Aggregation (experimental)
oldest_hero = dj(Hero).order_by("-age").first()             # Find the oldest hero
hero_count = len(dj(Hero).all())                           # Count all heroes

Documentation

We're still decoding Djene's full potential. Stay tuned for comprehensive documentation.

Contributing

Want to help evolve Djene? Check out our Contributing Guidelines.

License

Djene is open-source under the MIT License, free for you to experiment and modify.

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

djene-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

djene-0.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file djene-0.0.1.tar.gz.

File metadata

  • Download URL: djene-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0

File hashes

Hashes for djene-0.0.1.tar.gz
Algorithm Hash digest
SHA256 350d7fe5e3958f1a8b52043f16c64a01a92cead2541d6d3d56b4e8a6ce901978
MD5 778a2c3ba278f505bcd0ace2dd9ae904
BLAKE2b-256 4e4091e9126125ae179eb3d06303504e556b79d8e52c5d2cc3db36273d2a65d3

See more details on using hashes here.

File details

Details for the file djene-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: djene-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0

File hashes

Hashes for djene-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e58e4ec5c9245a4bc96c94a9c01b292fa4d8c685326f29a285b241b12813122b
MD5 44b8fe59c21648054c8abd40af21c691
BLAKE2b-256 f6db1b37c600063eef49551135403abacbb22cf4e6503235f701c76d5d0414a7

See more details on using hashes here.

Supported by

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