Skip to main content

Nextcord-Ormar

Documentation Status

Formerly Nextcord-Tortoise

Nextcord-Ormar is a library to help integrate the async Django-inspired ORM Ormar with a Nextcord bot. It's designed to compliment the modular cog system of Nextcord. It also comes with NXAlembic, a preconfigured version of Alembic to help with creating and applying database migrations.

Nextcord-Ormar is still in active development, there may be breaking changes as the library is polished up. If you have any feedback, feel free to open an issue!

Quickstart

Install Nextcord-Ormar and Ormar with the correct database backend.

pip install nextcord-ormar ormar[sqlite]

Import Nextcord-Ormar's bot class and pass it your database URL.

from nextcord_ormar import Bot

bot = Bot(command_prefix="$", database_url="sqlite:///db.sqlite")

In your cog file, import OrmarApp to create an app, then use AppModel to create a database model. Define your model like a normal Ormar model.

If you prefer, you can also define your models elsewhere and import them into your cog.

import ormar
from nextcord_ormar import OrmarApp, AppModel

ModelMeta = OrmarApp.create_app("example")

class ExampleTable(AppModel):
    class Meta(ModelMeta):
        pass
    
    id = ormar.Integer(primary_key=True)
    discord_id = ormar.BigInteger()
    message = ormar.Text()

You can then use this model in your cog.

from nextcord.ext import commands

class Example(commands.Cog):
    def __init__(self, nextcord):
        self.nextcord = nextcord

    @commands.command("example")
    async def example(self, ctx: commands.Context, *args):
        new_example = await ExampleTable.objects.create(discord_id=ctx.author.id, message=args[0])
        await ctx.send("Hello!")

Before you can start the bot though, you'll need to set up migrations and the database. Create a file called nxalembic.ini in your project root folder and tell it how to import your bot.

[nxalembic]
module = example.demo
bot = bot

You can think of this as from module import bot, or in this instance, from example.demo import bot. NXAlembic will use it to import your bot along with your definitions for each model.

In the same folder, you can now use the nxalembic tool. Create migrations with

nxalembic migrate

Upgrade the database

nxalembic update

Your bot is now ready to start!

Roadmap

Other than bug fixes as they arise, the current plan is to just add the rest of the Alembic commands to NXAlembic. If there is a specific feature you want that is missing from either the bot integration or NXAlembic, feel free to open an issue.

Thanks to

Miguel Grinberg for Flask-Migrations which was a useful example.

Mike Bayer for SQLAlchemy and Alembic

Metadata

Release files for nextcord-ormar 0.3.3

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

Source distribution (sdist)

Source distribution for nextcord-ormar 0.3.3
File Size Uploaded Provenance Actions
nextcord-ormar-0.3.3.tar.gz 9.7 kB Without provenance Details for nextcord-ormar-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nextcord-ormar 0.3.3
File Interpreter ABI Platform Actions
nextcord_ormar-0.3.3-py3-none-any.whl Python 3 none any Details for nextcord_ormar-0.3.3-py3-none-any.whl

Total release size: 19.7 kB

Release files / nextcord-ormar-0.3.3.tar.gz

Download URL nextcord-ormar-0.3.3.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fedfcd52d48d7b985e99de8012aade07c8ce81d1900aba004a84d72e4faa51de
BLAKE2b-256 checksum
How to use checksums
8ffd862b146ef57117f9cfc12074f20ae1bad97fd1e93cee8f52e2d08f4ccb9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.10.2 Linux/5.15.0-1014-azure

Release files / nextcord_ormar-0.3.3-py3-none-any.whl

Download URL nextcord_ormar-0.3.3-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e19d6fbf5d377564a6983893cecc459e0e0c43ee331f2c3a4e8d26dbcb0c9346
BLAKE2b-256 checksum
How to use checksums
b1e6b547c91e9197fdb95fbc8fe7eda0dd2f831a2be33fc5a53bd5b6ae123780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.10.2 Linux/5.15.0-1014-azure

Security for nextcord-ormar 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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