Skip to main content

Nestipy Logo

Version Python License

NestipyDB

NestipyDB is the official database module for Nestipy. It is built on top of Edgy and designed to be modular and configurable.

Installation

NestipyDB depends on Edgy. Make sure to follow the Edgy installation guide to set up dependencies for your specific database.

pip install nestipy-db

Usage

First, in your app_module.py, replace the url in DbConfig with your own:

from nestipy.common import Module
from nestipy_db import DbConfig, DbModule,AdminConfig

@Module(
    imports=[
        DbModule.for_root(
            DbConfig(
                url="sqlite:///db.sqlite",
                models=[],
                admin=AdminConfig(enable=True, url="/admin"), # if you need admin dashboard for model
            )
        ),
        # other modules...
    ]
)
class AppModule:
    ...

To load the config asynchronously, use DbModule.for_root_async:

from typing import Annotated
from nestipy.common import Module
from nestipy.ioc import Inject
from nestipy_config import ConfigModule, ConfigService, ConfigOption
from nestipy_db import DbConfig, DbModule

async def get_db_config(config: Annotated[ConfigService, Inject()]):
    return DbConfig(
        url=config.get("DATABASE_URL"),
        models=[]
    )

@Module(
    imports=[
        ConfigModule.for_root(ConfigOption(), is_global=True),
        DbModule.for_root_async(
            factory=get_db_config,
            inject=[ConfigService]
        ),
        # other modules...
    ]
)
class AppModule:
    ...

Models

Every model must be decorated with Model and must extends BaseModel from nestipy_db

from datetime import datetime
from uuid import UUID, uuid4

import edgy
from ..user.user_model import User
from nestipy_db import BaseModel, Model


@Model()
class Post(BaseModel):
    id: UUID = edgy.UUIDField(primary_key=True, default=uuid4, editable=False)
    title: str = edgy.CharField(max_length=256, default="")
    user: User = edgy.ForeignKey(User, on_delete=edgy.CASCADE, related_name="posts")
    reaction: list[User] = edgy.ManyToManyField(
        User, through_tablename=edgy.NEW_M2M_NAMING
    )
    created_at: datetime = edgy.DateTimeField(auto_now_add=True)
    updated_at: datetime = edgy.DateTimeField(auto_now=True)

Note

Note that, you need to register all of your models inside DbConfig(..., models=[]) or by importing DbModule.for_feature(Model1, Model2) in your current module.

CLI

NestipyDB aliases Edgy CLI commands and adds support for model generation. Instead of using edgy, use:

nestipy run db #follow edgy command

NestipyDB introduces a new model generation command:

nestipy run db new|g|gen|generate model_name module_name
  • module_name is optional.
  • If omitted, model_name will also be used as the module_name.
  • The model will be created inside the specified module, or the module folder will be created if it doesn't exist.

Admin

If admin is enabled, you can access it with the url specified in AdminConfig. The default credential for llogin is email: test@admin.com,password: admin. You can override this via AdminConfig. Other options are also available.

AdminPanel

Support

Nestipy is an MIT-licensed open source project. It continues to grow thanks to support from the community. If you'd like to contribute or sponsor, please [read more here].

Stay in Touch

License

Nestipy is MIT licensed.

Metadata

Release files for nestipy-db 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nestipy-db 0.3.0
File Size Uploaded
nestipy_db-0.3.0.tar.gz 811.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nestipy-db 0.3.0
File Interpreter ABI Platform
nestipy_db-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / nestipy_db-0.3.0.tar.gz

Download URL nestipy_db-0.3.0.tar.gz
Size 811.1 kB
Tags Source
SHA-256 checksum
How to use checksums
722c0006d56d37d653fb439a0459cd123142d31ed1c166ea818b6fcf1750188b
BLAKE2b-256 checksum
How to use checksums
14e86eb27fc7fbcd49f43b11ba224a878fba6c18815c47fa6052bc1e9303a2de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.21

Release files / nestipy_db-0.3.0-py3-none-any.whl

Download URL nestipy_db-0.3.0-py3-none-any.whl
Size 589.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71abf163a225a77fa43fac10c9bd9cebd365bfa36336b0b7d0292e2280653979
BLAKE2b-256 checksum
How to use checksums
d3041c188d8fccb42207ce73ed0174f7e442dd04058b1a51ff66db6ce714c8ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.21

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page