{"id":14080714,"url":"https://github.com/fastapi/sqlmodel","last_synced_at":"2026-02-20T18:09:32.262Z","repository":{"id":37026470,"uuid":"399495186","full_name":"fastapi/sqlmodel","owner":"fastapi","description":"SQL databases in Python, designed for simplicity, compatibility, and robustness.","archived":false,"fork":false,"pushed_at":"2025-09-05T08:35:02.000Z","size":5856,"stargazers_count":16705,"open_issues_count":137,"forks_count":752,"subscribers_count":139,"default_branch":"main","last_synced_at":"2025-09-05T10:24:37.848Z","etag":null,"topics":["fastapi","json","json-schema","pydantic","python","sql","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://sqlmodel.tiangolo.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["tiangolo"]}},"created_at":"2021-08-24T14:26:53.000Z","updated_at":"2025-09-05T10:02:46.000Z","dependencies_parsed_at":"2023-10-26T11:33:39.738Z","dependency_job_id":"6523abde-bc0b-4b80-915c-4ab326290c82","html_url":"https://github.com/fastapi/sqlmodel","commit_stats":{"total_commits":586,"total_committers":82,"mean_commits":7.146341463414634,"dds":0.5580204778156996,"last_synced_commit":"33b91794242342c20f267a0a65eeb6eb8c0ec098"},"previous_names":["fastapi/sqlmodel","tiangolo/sqlmodel"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/fastapi/sqlmodel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi%2Fsqlmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi%2Fsqlmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi%2Fsqlmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi%2Fsqlmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastapi","download_url":"https://codeload.github.com/fastapi/sqlmodel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastapi%2Fsqlmodel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274357409,"owners_count":25270674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","json","json-schema","pydantic","python","sql","sqlalchemy"],"created_at":"2024-08-13T12:01:30.719Z","updated_at":"2026-02-01T20:14:53.419Z","avatar_url":"https://github.com/fastapi.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://sqlmodel.tiangolo.com\"\u003e\u003cimg src=\"https://sqlmodel.tiangolo.com/img/logo-margin/logo-margin-vector.svg#only-light\" alt=\"SQLModel\"\u003e\u003c/a\u003e\n\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eSQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.\u003c/em\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/fastapi/sqlmodel/actions?query=workflow%3ATest+event%3Apush+branch%3Amain\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/fastapi/sqlmodel/actions/workflows/test.yml/badge.svg?event=push\u0026branch=main\" alt=\"Test\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/fastapi/sqlmodel/actions?query=workflow%3APublish\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/fastapi/sqlmodel/actions/workflows/publish.yml/badge.svg\" alt=\"Publish\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/sqlmodel\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://coverage-badge.samuelcolvin.workers.dev/fastapi/sqlmodel.svg\" alt=\"Coverage\"\u003e\n\u003ca href=\"https://pypi.org/project/sqlmodel\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/sqlmodel?color=%2334D058\u0026label=pypi%20package\" alt=\"Package version\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Documentation**: \u003ca href=\"https://sqlmodel.tiangolo.com\" target=\"_blank\"\u003ehttps://sqlmodel.tiangolo.com\u003c/a\u003e\n\n**Source Code**: \u003ca href=\"https://github.com/fastapi/sqlmodel\" target=\"_blank\"\u003ehttps://github.com/fastapi/sqlmodel\u003c/a\u003e\n\n---\n\nSQLModel is a library for interacting with \u003cabbr title='Also called \"Relational databases\"'\u003eSQL databases\u003c/abbr\u003e from Python code, with Python objects. It is designed to be intuitive, easy to use, highly compatible, and robust.\n\n**SQLModel** is based on Python type annotations, and powered by \u003ca href=\"https://pydantic-docs.helpmanual.io/\" class=\"external-link\" target=\"_blank\"\u003ePydantic\u003c/a\u003e and \u003ca href=\"https://sqlalchemy.org/\" class=\"external-link\" target=\"_blank\"\u003eSQLAlchemy\u003c/a\u003e.\n\nThe key features are:\n\n* **Intuitive to write**: Great editor support. \u003cabbr title=\"also known as auto-complete, autocompletion, IntelliSense\"\u003eCompletion\u003c/abbr\u003e everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.\n* **Easy to use**: It has sensible defaults and does a lot of work underneath to simplify the code you write.\n* **Compatible**: It is designed to be compatible with **FastAPI**, Pydantic, and SQLAlchemy.\n* **Extensible**: You have all the power of SQLAlchemy and Pydantic underneath.\n* **Short**: Minimize code duplication. A single type annotation does a lot of work. No need to duplicate models in SQLAlchemy and Pydantic.\n\n## Sponsors\n\n\u003c!-- sponsors --\u003e\n\n\u003ca href=\"https://www.govcert.lu\" target=\"_blank\" title=\"This project is being supported by GOVCERT.LU\"\u003e\u003cimg src=\"https://sqlmodel.tiangolo.com/img/sponsors/govcert.png\"\u003e\u003c/a\u003e\n\n\u003c!-- /sponsors --\u003e\n\n## SQL Databases in FastAPI\n\n\u003ca href=\"https://fastapi.tiangolo.com\" target=\"_blank\"\u003e\u003cimg src=\"https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png\" style=\"width: 20%;\"\u003e\u003c/a\u003e\n\n**SQLModel** is designed to simplify interacting with SQL databases in \u003ca href=\"https://fastapi.tiangolo.com\" class=\"external-link\" target=\"_blank\"\u003eFastAPI\u003c/a\u003e applications, it was created by the same \u003ca href=\"https://tiangolo.com/\" class=\"external-link\" target=\"_blank\"\u003eauthor\u003c/a\u003e. 😁\n\nIt 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.\n\n**SQLModel** is, in fact, a thin layer on top of **Pydantic** and **SQLAlchemy**, carefully designed to be compatible with both.\n\n## Requirements\n\nA recent and currently supported \u003ca href=\"https://www.python.org/downloads/\" class=\"external-link\" target=\"_blank\"\u003eversion of Python\u003c/a\u003e.\n\nAs **SQLModel** is based on **Pydantic** and **SQLAlchemy**, it requires them. They will be automatically installed when you install SQLModel.\n\n## Installation\n\nMake sure you create a \u003ca href=\"https://sqlmodel.tiangolo.com/virtual-environments/\" class=\"external-link\" target=\"_blank\"\u003evirtual environment\u003c/a\u003e, activate it, and then install SQLModel, for example with:\n\n\u003cdiv class=\"termy\"\u003e\n\n```console\n$ pip install sqlmodel\n---\u003e 100%\nSuccessfully installed sqlmodel\n```\n\n\u003c/div\u003e\n\n## Example\n\nFor an introduction to databases, SQL, and everything else, see the \u003ca href=\"https://sqlmodel.tiangolo.com/databases/\" target=\"_blank\"\u003eSQLModel documentation\u003c/a\u003e.\n\nHere's a quick example. ✨\n\n### A SQL Table\n\nImagine you have a SQL table called `hero` with:\n\n* `id`\n* `name`\n* `secret_name`\n* `age`\n\nAnd you want it to have this data:\n\n| id | name | secret_name | age |\n-----|------|-------------|------|\n| 1  | Deadpond | Dive Wilson | null |\n| 2  | Spider-Boy | Pedro Parqueador | null |\n| 3  | Rusty-Man | Tommy Sharp | 48 |\n\n### Create a SQLModel Model\n\nThen you could create a **SQLModel** model like this:\n\n```Python\nfrom sqlmodel import Field, SQLModel\n\n\nclass Hero(SQLModel, table=True):\n    id: int | None = Field(default=None, primary_key=True)\n    name: str\n    secret_name: str\n    age: int | None = None\n```\n\nThat class `Hero` is a **SQLModel** model, the equivalent of a SQL table in Python code.\n\nAnd each of those class attributes is equivalent to each **table column**.\n\n### Create Rows\n\nThen you could **create each row** of the table as an **instance** of the model:\n\n```Python\nhero_1 = Hero(name=\"Deadpond\", secret_name=\"Dive Wilson\")\nhero_2 = Hero(name=\"Spider-Boy\", secret_name=\"Pedro Parqueador\")\nhero_3 = Hero(name=\"Rusty-Man\", secret_name=\"Tommy Sharp\", age=48)\n```\n\nThis way, you can use conventional Python code with **classes** and **instances** that represent **tables** and **rows**, and that way communicate with the **SQL database**.\n\n### Editor Support\n\nEverything is designed for you to get the best developer experience possible, with the best editor support.\n\nIncluding **autocompletion**:\n\n\u003cimg class=\"shadow\" src=\"https://sqlmodel.tiangolo.com/img/index/autocompletion01.png\"\u003e\n\nAnd **inline errors**:\n\n\u003cimg class=\"shadow\" src=\"https://sqlmodel.tiangolo.com/img/index/inline-errors01.png\"\u003e\n\n### Write to the Database\n\nYou 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:\n\n```Python hl_lines=\"16  19  21-25\"\nfrom sqlmodel import Field, Session, SQLModel, create_engine\n\n\nclass Hero(SQLModel, table=True):\n    id: int | None = Field(default=None, primary_key=True)\n    name: str\n    secret_name: str\n    age: int | None = None\n\n\nhero_1 = Hero(name=\"Deadpond\", secret_name=\"Dive Wilson\")\nhero_2 = Hero(name=\"Spider-Boy\", secret_name=\"Pedro Parqueador\")\nhero_3 = Hero(name=\"Rusty-Man\", secret_name=\"Tommy Sharp\", age=48)\n\n\nengine = create_engine(\"sqlite:///database.db\")\n\n\nSQLModel.metadata.create_all(engine)\n\nwith Session(engine) as session:\n    session.add(hero_1)\n    session.add(hero_2)\n    session.add(hero_3)\n    session.commit()\n```\n\nThat will save a **SQLite** database with the 3 heroes.\n\n### Select from the Database\n\nThen you could write queries to select from that same database, for example with:\n\n```Python hl_lines=\"13-17\"\nfrom sqlmodel import Field, Session, SQLModel, create_engine, select\n\n\nclass Hero(SQLModel, table=True):\n    id: int | None = Field(default=None, primary_key=True)\n    name: str\n    secret_name: str\n    age: int | None = None\n\n\nengine = create_engine(\"sqlite:///database.db\")\n\nwith Session(engine) as session:\n    statement = select(Hero).where(Hero.name == \"Spider-Boy\")\n    hero = session.exec(statement).first()\n    print(hero)\n```\n\n### Editor Support Everywhere\n\n**SQLModel** was carefully designed to give you the best developer experience and editor support, **even after selecting data** from the database:\n\n\u003cimg class=\"shadow\" src=\"https://sqlmodel.tiangolo.com/img/index/autocompletion02.png\"\u003e\n\n## SQLAlchemy and Pydantic\n\nThat class `Hero` is a **SQLModel** model.\n\nBut 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**.\n\nAnd 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**.\n\n## License\n\nThis project is licensed under the terms of the [MIT license](https://github.com/fastapi/sqlmodel/blob/main/LICENSE).\n","funding_links":["https://github.com/sponsors/tiangolo"],"categories":["ORM","Python","HarmonyOS","sql","Database Clients","\u003ca name=\"Python\"\u003e\u003c/a\u003ePython"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastapi%2Fsqlmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastapi%2Fsqlmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastapi%2Fsqlmodel/lists"}