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.9.tar.gz (122.8 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.9-py3-none-any.whl (123.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_studio-0.1.9.tar.gz
  • Upload date:
  • Size: 122.8 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.9.tar.gz
Algorithm Hash digest
SHA256 cf2e7095784e339bfd242da932f043e0edaa127892f70b05e0a173a82c6de141
MD5 c911408eaf69b8d54443cd7d03643325
BLAKE2b-256 c8485d8419292d569dc66cb091a9c454e27826a3bf6fcc0d06d46b7e9fd4d466

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlalchemy_studio-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ae68e9f4570321a2580daa0ff666001a8de25b5402ddef34ba219b12f0831c4e
MD5 42afab0d1c339fce57bfc4aa7b276836
BLAKE2b-256 e65d2718ea3b7234eb49fd4c561b3106221ccd714d2ec96973abdf4778602696

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