Skip to main content

FastAPI studio for inspecting SQLAlchemy databases

Project description

sqlalchemy-studio

FastAPI studio for inspecting and querying SQLAlchemy databases.

Installation

Install from PyPI:

pip install sqlalchemy-studio

Or install the latest version from GitHub:

pip install --upgrade git+https://github.com/coderxuz/sqlalchemy-studio.git@main#subdirectory=sqlalchemy-studio-backend

Usage

Create a normal SQLAlchemy engine and declarative base, then pass them to Studio.

from sqlalchemy import Integer, String, create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column

from sqlalchemy_studio import Studio


class Base(DeclarativeBase):
    pass


class User(Base):
    __tablename__ = "users"

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    username: Mapped[str] = mapped_column(String(50), nullable=False)
    email: Mapped[str] = mapped_column(String(120), nullable=False)


engine = create_engine("sqlite:///app.db")


def seed_data() -> None:
    Base.metadata.create_all(engine)

    with Session(engine) as session:
        if session.query(User).count() == 0:
            session.add_all(
                [
                    User(username="john", email="john@example.com"),
                    User(username="alice", email="alice@example.com"),
                ]
            )
            session.commit()


if __name__ == "__main__":
    seed_data()
    Studio(engine=engine, base=Base).run(port=7000)

Run the script:

python app.py

Open http://localhost:7000 in your browser.

Example dashboard

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

sqlalchemy_studio-0.1.8.tar.gz (121.3 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_studio-0.1.8-py3-none-any.whl (122.2 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_studio-0.1.8.tar.gz.

File metadata

  • Download URL: sqlalchemy_studio-0.1.8.tar.gz
  • Upload date:
  • Size: 121.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for sqlalchemy_studio-0.1.8.tar.gz
Algorithm Hash digest
SHA256 374d28138e8ea62e0f0b1b2669dcfe8e71c5f602d0695719907aeef4df92f604
MD5 46a68cc404be0bd06cb32c470e10c718
BLAKE2b-256 e4d99195e73add5f23fc0d8e8bedc0445fa3a24e24387d455ffca61cc5272943

See more details on using hashes here.

File details

Details for the file sqlalchemy_studio-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_studio-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5e75c5a76f91870e9a14c046fbd87c6c974bafaae45a2a4c478fe73f8cedf3b8
MD5 0e9f84d5b48b18c700ccc33fe25efc03
BLAKE2b-256 9f0662b8f8b25e9f38b8821f93fdf00106da3ba0bf06e92f913d4b4e41e9cb51

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