Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.8%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: ObedMokuaNyandiri
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 4.38 MB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 8
  • Releases: 0
Created almost 2 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Contributing Funding License Citation Security

README.md

SQLModel

SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.

Test Publish Coverage Package version


Documentation: https://sqlmodel.tiangolo.com

Source Code: https://github.com/tiangolo/sqlmodel


SQLModel is a library for interacting with SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, highly compatible, and robust.

SQLModel is based on Python type annotations, and powered by Pydantic and SQLAlchemy.

The key features are:

  • Intuitive to write: Great editor support. Completion everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.
  • Easy to use: It has sensible defaults and does a lot of work underneath to simplify the code you write.
  • Compatible: It is designed to be compatible with FastAPI, Pydantic, and SQLAlchemy.
  • Extensible: You have all the power of SQLAlchemy and Pydantic underneath.
  • Short: Minimize code duplication. A single type annotation does a lot of work. No need to duplicate models in SQLAlchemy and Pydantic.

Sponsors

SQL Databases in FastAPI

SQLModel is designed to simplify interacting with SQL databases in FastAPI applications, it was created by the same author. 😁

It combines SQLAlchemy and Pydantic and tries to simplify the code you write as much as possible, allowing you to reduce the code duplication to a minimum, but while getting the best developer experience possible.

SQLModel is, in fact, a thin layer on top of Pydantic and SQLAlchemy, carefully designed to be compatible with both.

Requirements

A recent and currently supported version of Python.

As SQLModel is based on Pydantic and SQLAlchemy, it requires them. They will be automatically installed when you install SQLModel.

Installation

```console $ pip install sqlmodel ---> 100% Successfully installed sqlmodel ```

Example

For an introduction to databases, SQL, and everything else, see the SQLModel documentation.

Here's a quick example. ✨

A SQL Table

Imagine you have a SQL table called hero with:

  • id
  • name
  • secret_name
  • age

And you want it to have this data:

| id | name | secret_name | age | -----|------|-------------|------| | 1 | Deadpond | Dive Wilson | null | | 2 | Spider-Boy | Pedro Parqueador | null | | 3 | Rusty-Man | Tommy Sharp | 48 |

Create a SQLModel Model

Then you could create a SQLModel model like this:

```Python from typing import Optional

from sqlmodel import Field, SQLModel

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

That class Hero is a SQLModel model, the equivalent of a SQL table in Python code.

And each of those class attributes is equivalent to each table column.

Create Rows

Then you could create each row of the table as an instance of the model:

Python hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") hero_2 = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") hero_3 = Hero(name="Rusty-Man", secret_name="Tommy Sharp", age=48)

This way, you can use conventional Python code with classes and instances that represent tables and rows, and that way communicate with the SQL database.

Editor Support

Everything is designed for you to get the best developer experience possible, with the best editor support.

Including autocompletion:

And inline errors:

Write to the Database

You can learn a lot more about SQLModel by quickly following the tutorial, but if you need a taste right now of how to put all that together and save to the database, you can do this:

```Python hl_lines="18 21 23-27" from typing import Optional

from sqlmodel import Field, Session, SQLModel, create_engine

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

hero1 = Hero(name="Deadpond", secretname="Dive Wilson") hero2 = Hero(name="Spider-Boy", secretname="Pedro Parqueador") hero3 = Hero(name="Rusty-Man", secretname="Tommy Sharp", age=48)

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

SQLModel.metadata.create_all(engine)

with Session(engine) as session: session.add(hero1) session.add(hero2) session.add(hero_3) session.commit() ```

That will save a SQLite database with the 3 heroes.

Select from the Database

Then you could write queries to select from that same database, for example with:

```Python hl_lines="15-18" from typing import Optional

from sqlmodel import Field, Session, SQLModel, create_engine, select

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

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

with Session(engine) as session: statement = select(Hero).where(Hero.name == "Spider-Boy") hero = session.exec(statement).first() print(hero) ```

Editor Support Everywhere

SQLModel was carefully designed to give you the best developer experience and editor support, even after selecting data from the database:

SQLAlchemy and Pydantic

That class Hero is a SQLModel model.

But at the same time, ✨ it is a SQLAlchemy model ✨. So, you can combine it and use it with other SQLAlchemy models, or you could easily migrate applications with SQLAlchemy to SQLModel.

And at the same time, ✨ it is also a Pydantic model ✨. You can use inheritance with it to define all your data models while avoiding code duplication. That makes it very easy to use with FastAPI.

License

This project is licensed under the terms of the MIT license.

Owner

  • Name: OBED MOKUA NYANDIRI
  • Login: ObedMokuaNyandiri
  • Kind: user

Hi there! I'm an IT student passionate about technology and its potential to change the world. Feel free to reach out and collaborate.

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: SQLModel
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Sebastián
    family-names: Ramírez
    email: tiangolo@gmail.com
identifiers:
repository-code: 'https://github.com/tiangolo/sqlmodel'
url: 'https://sqlmodel.tiangolo.com'
abstract: >-
  SQLModel, SQL databases in Python, designed for
  simplicity, compatibility, and robustness.
keywords:
  - fastapi
  - pydantic
  - sqlalchemy
license: MIT

GitHub Events

Total
Last Year

Dependencies

.github/actions/comment-docs-preview-in-pr/action.yml actions
  • Dockerfile * docker
.github/workflows/build-docs.yml actions
  • actions/cache v3 composite
  • actions/checkout v4 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • dorny/paths-filter v2 composite
  • re-actors/alls-green release/v1 composite
.github/workflows/deploy-docs.yml actions
  • ./.github/actions/comment-docs-preview-in-pr * composite
  • actions/checkout v4 composite
  • cloudflare/pages-action v1 composite
  • dawidd6/action-download-artifact v2.28.0 composite
.github/workflows/issue-manager.yml actions
  • tiangolo/issue-manager 0.4.1 composite
.github/workflows/latest-changes.yml actions
  • actions/checkout v4 composite
  • docker://tiangolo/latest-changes 0.2.0 composite
  • mxschmitt/action-tmate v3 composite
.github/workflows/publish.yml actions
  • actions/cache v3 composite
  • actions/checkout v4 composite
  • actions/setup-python v4 composite
  • mxschmitt/action-tmate v3 composite
.github/workflows/smokeshow.yml actions
  • actions/setup-python v4 composite
  • dawidd6/action-download-artifact v2.28.0 composite
.github/workflows/test.yml actions
  • actions/cache v3 composite
  • actions/checkout v4 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • mxschmitt/action-tmate v3 composite
  • re-actors/alls-green release/v1 composite
.github/actions/comment-docs-preview-in-pr/Dockerfile docker
  • python 3.7 build
pyproject.toml pypi
  • black >=22.10,<24.0 develop
  • cairosvg ^2.5.2 develop
  • coverage >=6.2,<8.0 develop
  • dirty-equals ^0.6.0 develop
  • fastapi ^0.103.2 develop
  • httpx 0.24.1 develop
  • mdx-include ^1.4.1 develop
  • mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0 develop
  • mkdocs-material 9.2.7 develop
  • mypy 1.4.1 develop
  • pillow ^9.3.0 develop
  • pytest ^7.0.1 develop
  • ruff ^0.1.2 develop
  • typer-cli ^0.0.13 develop
  • SQLAlchemy >=2.0.0,<2.1.0
  • pydantic >=1.10.13,<3.0.0
  • python ^3.7