{"id":13460198,"url":"https://github.com/tortoise/tortoise-orm","last_synced_at":"2026-03-05T09:04:57.022Z","repository":{"id":37663667,"uuid":"127320882","full_name":"tortoise/tortoise-orm","owner":"tortoise","description":"Familiar asyncio ORM for python, built with relations in mind","archived":false,"fork":false,"pushed_at":"2026-02-16T09:17:45.000Z","size":6653,"stargazers_count":5496,"open_issues_count":482,"forks_count":460,"subscribers_count":42,"default_branch":"develop","last_synced_at":"2026-02-16T18:07:28.559Z","etag":null,"topics":["async","asyncio","mysql","orm","postgresql","python3","sqlite"],"latest_commit_sha":null,"homepage":"https://tortoise.github.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tortoise.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"docs/CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":"docs/CODE_OF_CONDUCT.rst","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"docs/roadmap.rst","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":["https://sponsor.long2ice.io"]}},"created_at":"2018-03-29T16:52:10.000Z","updated_at":"2026-02-15T17:00:58.000Z","dependencies_parsed_at":"2024-01-05T21:20:16.740Z","dependency_job_id":"402bc0c3-929a-4441-a2ed-b47c45a47701","html_url":"https://github.com/tortoise/tortoise-orm","commit_stats":{"total_commits":1010,"total_committers":124,"mean_commits":8.14516129032258,"dds":0.6217821782178218,"last_synced_commit":"cf59c709b9b2af80e4ea1b5a6896e9265e567362"},"previous_names":[],"tags_count":128,"template":false,"template_full_name":null,"purl":"pkg:github/tortoise/tortoise-orm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tortoise%2Ftortoise-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tortoise%2Ftortoise-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tortoise%2Ftortoise-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tortoise%2Ftortoise-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tortoise","download_url":"https://codeload.github.com/tortoise/tortoise-orm/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tortoise%2Ftortoise-orm/sbom","scorecard":{"id":895119,"data":{"date":"2025-08-11","repo":{"name":"github.com/tortoise/tortoise-orm","commit":"8a131896208d728b7734ad8fbebe1a046e8db24b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.8,"checks":[{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Warn: no topLevel permission defined: .github/workflows/codspeed.yml:1","Warn: no topLevel permission defined: .github/workflows/gh-pages-release.yml:1","Warn: no topLevel permission defined: .github/workflows/gh-pages.yml:1","Warn: no topLevel permission defined: .github/workflows/pypi.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":10,"reason":"12 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/ci.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/ci.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/ci.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codspeed.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/codspeed.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codspeed.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/codspeed.yml/develop?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/codspeed.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/codspeed.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages-release.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/gh-pages-release.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages-release.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/gh-pages-release.yml/develop?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/gh-pages-release.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/gh-pages-release.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/gh-pages.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/gh-pages.yml/develop?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/gh-pages.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pypi.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/pypi.yml/develop?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pypi.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/pypi.yml/develop?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/pypi.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/tortoise/tortoise-orm/pypi.yml/develop?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/ci.yml:62","Warn: pipCommand not pinned by hash: .github/workflows/ci.yml:85","Warn: pipCommand not pinned by hash: .github/workflows/ci.yml:99","Warn: pipCommand not pinned by hash: .github/workflows/codspeed.yml:25","Warn: pipCommand not pinned by hash: .github/workflows/gh-pages-release.yml:16","Warn: pipCommand not pinned by hash: .github/workflows/gh-pages.yml:17","Warn: pipCommand not pinned by hash: .github/workflows/pypi.yml:16","Info:   0 out of  11 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   4 third-party GitHubAction dependencies pinned","Info:   0 out of   7 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/pypi.yml:7"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-79v4-65xg-pq4g","Warn: Project is vulnerable to: GHSA-9hjg-9r4m-mvj7","Warn: Project is vulnerable to: GHSA-2c2j-9gv5-cj73"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T13:23:42.409Z","repository_id":37663667,"created_at":"2025-08-24T13:23:42.409Z","updated_at":"2025-08-24T13:23:42.409Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29636034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T22:32:43.237Z","status":"ssl_error","status_checked_at":"2026-02-19T22:32:38.330Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async","asyncio","mysql","orm","postgresql","python3","sqlite"],"created_at":"2024-07-31T10:00:37.204Z","updated_at":"2026-02-19T23:01:08.418Z","avatar_url":"https://github.com/tortoise.png","language":"Python","readme":"============\nTortoise ORM\n============\n\n.. image:: https://img.shields.io/pypi/v/tortoise-orm.svg?style=flat\n   :target: https://pypi.python.org/pypi/tortoise-orm\n.. image:: https://pepy.tech/badge/tortoise-orm/month\n   :target: https://pepy.tech/project/tortoise-orm\n.. image:: https://github.com/tortoise/tortoise-orm/workflows/gh-pages/badge.svg\n   :target: https://github.com/tortoise/tortoise-orm/actions?query=workflow:gh-pages\n.. image:: https://github.com/tortoise/tortoise-orm/actions/workflows/ci.yml/badge.svg?branch=develop\n   :target: https://github.com/tortoise/tortoise-orm/actions?query=workflow:ci\n.. image:: https://coveralls.io/repos/github/tortoise/tortoise-orm/badge.svg\n   :target: https://coveralls.io/github/tortoise/tortoise-orm\n\nIntroduction\n============\n\nTortoise ORM is an easy-to-use ``asyncio`` ORM *(Object Relational Mapper)* inspired by Django.\n\nYou can find the docs at `Documentation \u003chttps://tortoise.github.io\u003e`_\n\nTortoise ORM supports CPython 3.10 and later for SQLite, MySQL, PostgreSQL, Microsoft SQL Server, and Oracle.\n\nWhy was Tortoise ORM built?\n---------------------------\n\nTortoise ORM was built to provide a lightweight, async-native Object-Relational Mapper for Python with a familiar Django-like API.\n\nTortoise ORM performs well when compared to other Python ORMs. Here are `our benchmarks \u003chttps://github.com/tortoise/orm-benchmarks\u003e`_ on PostgreSQL 17, where we measure different read and write operations (rows/sec, more is better):\n\n.. image:: https://raw.githubusercontent.com/tortoise/tortoise-orm/develop/docs/ORM_Perf.png\n    :target: https://github.com/tortoise/orm-benchmarks\n\nHow is an ORM useful?\n---------------------\n\nAn Object-Relational Mapper (ORM) abstracts database interactions, allowing developers to work with databases using high-level, object-oriented code instead of raw SQL.\n\n* Reduces boilerplate SQL, allowing faster development with cleaner, more readable code.\n* Helps prevent SQL injection by using parameterized queries.\n* Centralized schema and relationship definitions make code easier to manage and modify.\n* Handles schema changes through version-controlled migrations.\n\nGetting Started\n===============\n\nInstallation\n------------\n\nThe following table shows the available installation options for different databases (note that there are multiple options of clients for some databases):\n\n.. list-table:: Available Installation Options\n   :header-rows: 1\n   :widths: 30 70\n\n   * - Database\n     - Installation Command\n   * - SQLite\n     - ``pip install tortoise-orm``\n   * - PostgreSQL (psycopg)\n     - ``pip install tortoise-orm[psycopg]``\n   * - PostgreSQL (asyncpg)\n     - ``pip install tortoise-orm[asyncpg]``\n   * - MySQL (aiomysql)\n     - ``pip install tortoise-orm[aiomysql]``\n   * - MySQL (asyncmy)\n     - ``pip install tortoise-orm[asyncmy]``\n   * - MS SQL\n     - ``pip install tortoise-orm[asyncodbc]``\n   * - Oracle\n     - ``pip install tortoise-orm[asyncodbc]``\n\n\nQuick Tutorial\n--------------\n\nDefine the models by inheriting from ``tortoise.models.Model``.\n\n\n.. code-block:: python3\n\n    from tortoise.models import Model\n    from tortoise import fields\n\n    class Tournament(Model):\n        id = fields.IntField(primary_key=True)\n        name = fields.CharField(max_length=20)\n\n\n    class Event(Model):\n        id = fields.BigIntField(primary_key=True)\n        name = fields.TextField()\n        tournament = fields.ForeignKeyField('models.Tournament', related_name='events', on_delete=fields.OnDelete.CASCADE)\n        participants = fields.ManyToManyField('models.Team', related_name='events', through='event_team', on_delete=fields.OnDelete.SET_NULL)\n\n\n    class Team(Model):\n        id = fields.UUIDField(primary_key=True)\n        name = fields.CharField(max_length=20, unique=True)\n\n\nAfter defining the models, Tortoise ORM needs to be initialized to establish the relationships between models and connect to the database.\nThe code below creates a connection to a SQLite DB database with the ``aiosqlite`` client. ``generate_schema`` sets up schema on an empty database.\n``generate_schema`` is for development purposes only; use the built-in\nmigrations for production use.\n\n.. code-block:: python3\n\n    from tortoise import Tortoise, run_async\n\n    async def init():\n        # Here we connect to a SQLite DB file.\n        # also specify the app name of \"models\"\n        # which contain models from \"app.models\"\n        await Tortoise.init(\n            db_url='sqlite://db.sqlite3',\n            modules={'models': ['app.models']}\n        )\n        # Generate the schema\n        await Tortoise.generate_schemas()\n\n    run_async(main())\n\n``run_async`` is a helper function to run simple Tortoise scripts. Check out `Documentation \u003chttps://tortoise.github.io\u003e`_ for FastAPI, Sanic and other integrations.\n\nWith the Tortoise initialized, the models are available for use:\n\n.. code-block:: python3\n\n    async def main():\n        await Tortoise.init(\n            db_url='sqlite://db.sqlite3',\n            modules={'models': ['app.models']}\n        )\n        await Tortoise.generate_schemas()\n\n        # Creating an instance with .save()\n        tournament = Tournament(name='New Tournament')\n        await tournament.save()\n\n        # Or with .create()\n        await Event.create(name='Without participants', tournament=tournament)\n        event = await Event.create(name='Test', tournament=tournament)\n        participants = []\n        for i in range(2):\n            team = await Team.create(name='Team {}'.format(i + 1))\n            participants.append(team)\n\n        # One to Many (ForeignKey) relations support creating related objects\n        another_event = await tournament.events.create(name='Another Event')\n\n        # Many to Many Relationship management is quite straightforward\n        # (there are .remove(...) and .clear() too)\n        await event.participants.add(*participants)\n\n        # Iterate over related entities with the async context manager\n        async for team in event.participants:\n            print(team.name)\n\n        # The related entities are cached and can be iterated in the synchronous way afterwards\n        for team in event.participants:\n            pass\n\n        # Use prefetch_related to fetch related objects\n        selected_events = await Event.filter(\n            participants=participants[0].id\n        ).prefetch_related('participants', 'tournament')\n        for event in selected_events:\n            print(event.tournament.name)\n            print([t.name for t in event.participants])\n\n        # Prefetch multiple levels of related entities\n        await Team.all().prefetch_related('events__tournament')\n\n        # Filter and order by related models too\n        await Tournament.filter(\n            events__name__in=['Test', 'Prod']\n        ).order_by('-events__participants__name').distinct()\n\n    run_async(main())\n\n\nLearn more at the `documentation site \u003chttps://tortoise.github.io\u003e`_\n\n\nMigrations\n==========\n\nTortoise ORM ships with a built-in migration framework and CLI.\nAutodetect model changes, generate migration files, and apply them:\n\n.. code-block:: shell\n\n    tortoise init                # create migration packages\n    tortoise makemigrations      # detect changes and generate migrations\n    tortoise migrate             # apply pending migrations\n    tortoise sqlmigrate app 001  # preview SQL without executing\n\nMigrations support ``RunPython`` and ``RunSQL`` for data migrations, offline migration generation,\nreversible operations, and multi-app and multi db-schema projects.\n\nSee the `migrations documentation \u003chttps://tortoise.github.io/migration.html\u003e`_ for\nfull setup and examples.\n\nContributing\n============\n\nPlease have a look at the `Contribution Guide \u003cdocs/CONTRIBUTING.rst\u003e`_.\n\nLicense\n=======\n\nThis project is licensed under the Apache License - see the `LICENSE.txt \u003cLICENSE.txt\u003e`_ file for details.\n","funding_links":["https://sponsor.long2ice.io"],"categories":["Python","ORM","Data Management \u0026 Processing","HarmonyOS","Extensions","语言资源库","Database Clients","📚 فهرست","Database Drivers"],"sub_categories":["Database \u0026 Cloud Management","Windows Manager","ORM","python","دیتابیس"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftortoise%2Ftortoise-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftortoise%2Ftortoise-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftortoise%2Ftortoise-orm/lists"}