{"id":22972630,"url":"https://github.com/cainmagi/flask-sqlalchemy-compat","last_synced_at":"2026-05-18T10:35:00.650Z","repository":{"id":267356832,"uuid":"900959960","full_name":"cainmagi/flask-sqlalchemy-compat","owner":"cainmagi","description":"Support the compatibility between flask_sqlalchemy and flask_sqlalchemy_lite.","archived":false,"fork":false,"pushed_at":"2025-04-04T21:29:36.000Z","size":625,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T21:12:54.736Z","etag":null,"topics":["compatibility","compatibility-layer","flask","flask-sqlalchemy","flask-sqlalchemy-lite","python","python-library","python3","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://cainmagi.github.io/flask-sqlalchemy-compat/","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/cainmagi.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"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}},"created_at":"2024-12-09T19:34:23.000Z","updated_at":"2024-12-31T17:12:45.000Z","dependencies_parsed_at":"2025-09-05T01:32:32.645Z","dependency_job_id":"a83fa84c-8894-4bda-8ec1-58756d14a53b","html_url":"https://github.com/cainmagi/flask-sqlalchemy-compat","commit_stats":null,"previous_names":["cainmagi/flask-sqlalchemy-compat"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/cainmagi/flask-sqlalchemy-compat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fflask-sqlalchemy-compat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fflask-sqlalchemy-compat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fflask-sqlalchemy-compat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fflask-sqlalchemy-compat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cainmagi","download_url":"https://codeload.github.com/cainmagi/flask-sqlalchemy-compat/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fflask-sqlalchemy-compat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33174873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["compatibility","compatibility-layer","flask","flask-sqlalchemy","flask-sqlalchemy-lite","python","python-library","python3","sqlalchemy"],"created_at":"2024-12-14T23:18:14.008Z","updated_at":"2026-05-18T10:34:55.640Z","avatar_url":"https://github.com/cainmagi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask SQLAlchemy Compat\n\n\u003cp\u003e\u003cimg alt=\"Banner\" src=\"https://repository-images.githubusercontent.com/900959960/5fa49b35-0f23-4e6d-9c00-b57ff6e513fd\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/cainmagi/flask-sqlalchemy-compat/releases/latest\"\u003e\u003cimg alt=\"GitHub release (latest SemVer)\" src=\"https://img.shields.io/github/v/release/cainmagi/flask-sqlalchemy-compat?logo=github\u0026sort=semver\u0026style=flat-square\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/cainmagi/flask-sqlalchemy-compat/releases\"\u003e\u003cimg alt=\"GitHub all releases\" src=\"https://img.shields.io/github/downloads/cainmagi/flask-sqlalchemy-compat/total?logo=github\u0026style=flat-square\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/cainmagi/flask-sqlalchemy-compat/blob/main/LICENSE\"\u003e\u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/cainmagi/flask-sqlalchemy-compat?style=flat-square\u0026logo=opensourceinitiative\u0026logoColor=white\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/flask-sqlalchemy-compat\"\u003e\u003cimg alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/flask-sqlalchemy-compat?style=flat-square\u0026logo=pypi\u0026logoColor=white\u0026label=pypi\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/cainmagi/flask-sqlalchemy-compat/actions/workflows/python-package.yml\"\u003e\u003cimg alt=\"GitHub Actions (Build)\" src=\"https://img.shields.io/github/actions/workflow/status/cainmagi/flask-sqlalchemy-compat/python-package.yml?style=flat-square\u0026logo=githubactions\u0026logoColor=white\u0026label=build\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/cainmagi/flask-sqlalchemy-compat/actions/workflows/python-publish.yml\"\u003e\u003cimg alt=\"GitHub Actions (Release)\" src=\"https://img.shields.io/github/actions/workflow/status/cainmagi/flask-sqlalchemy-compat/python-publish.yml?style=flat-square\u0026logo=githubactions\u0026logoColor=white\u0026label=release\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nSupport the compatibility between `flask_sqlalchemy` and `flask_sqlalchemy_lite`. It allows users to make minimal changes when they need to migrate from either one of these two packages to each other.\n\nThe main motivation of this package is because `flask_sqlalchemy_lite` does not support `python\u003c=3.8`. This package is designed for providing the similar usages when users have to make the `flask_sqlalchemy_lite` working with `python\u003c=3.8` by using `flask_sqlalchemy`. In this case, users can get rid of the difficulty of maintaining two sets of codes.\n\n\u003e [!WARNING]\n\u003e This package is designed for `sqlalchemy\u003e=2.0.0` only. If you are using an older version. You cannot use this package.\n\n\u003e [!WARNING]\n\u003e To make this package work with `python=3.7`, users should install an unofficial `flask-sqlalchemy` version.\n\n## 1. Install\n\nIntall the **latest released version** of this package by using the PyPI source:\n\n``` sh\npython -m pip install flask-sqlalchemy-compat\n```\n\nor use the following commands to install **the developing version** from the GitHub Source when you have already installed [Git :hammer:][tool-git]:\n\n```sh\npython -m pip install \"flask-sqlalchemy-compat[dev] @ git+https://github.com/cainmagi/flask-sqlalchemy-compat.git\"\n```\n\n\u003e [!WARNING]\n\u003e To make this package work with `python=3.7`, users should install an unofficial `flask-sqlalchemy` version. See\n\u003e\n\u003e https://github.com/pallets-eco/flask-sqlalchemy/issues/1140#issuecomment-1577921154\n\u003e\n\u003e This unofficial version can be installed by:\n\u003e ```sh\n\u003e python -m pip install flask-sqlalchemy-compat[backends]\n\u003e ```\n\n## 2. Usage\n\nWhen you are using `flask-sqlalchemy-lite`, using the following codes will let your codes fall back to the compatible mode if `flask-sqlalchemy-lite` is not installed but `flask-sqlalchemy` is installed.\n\n```python\nimport sqlalchemy as sa\nimport sqlalchemy.orm as sa_orm\nimport flask_sqlalchemy_compat as fsc\n\n\nclass _Base(sa_orm.DeclarativeBase): ...\n\n\ndb, Base = fsc.get_flask_sqlalchemy_lite(_Base)\n\n\nclass NewModel(Base):\n    __tablename__ = \"new_model\"\n\n    id: sa_orm.Mapped[int] = sa_orm.mapped_column(primary_key=True)\n    name: sa_orm.Mapped[str] = sa_orm.mapped_column()\n\n\nif __name__ == \"__main__\":\n    import os\n    import flask\n\n    app = flask.Flask(__name__, instance_path=os.path.abspath(\"./instance\"))\n    app.config.update({\"SQLALCHEMY_ENGINES\": {\"default\": \"sqlite:///main.db\"}})\n    db.init_app(app)\n\n    with app.app_context():\n        Base.metadata.create_all(db.engine)\n\n        db.session.add(NewModel(name=\"new\"))\n        db.session.commit()\n\n        model = db.session.scalar(sa.select(NewModel))\n        print(model.id, model.name) if model is not None else print(\"NOT FOUND.\")\n```\n\nThe above codes will works no matter `flask_sqlalchemy_lite` or `flask_sqlalchemy` is installed.\n\nSimilarly, the following example is designed for the codes written with `flask_sqlalchemy`. The codes fall back to the compatible mode if `flask-sqlalchemy` is not installed but `flask-sqlalchemy-lite` is installed.\n\n```python\nimport sqlalchemy as sa\nimport sqlalchemy.orm as sa_orm\nimport flask_sqlalchemy_compat as fsc\n\n\nclass _Base(sa_orm.DeclarativeBase): ...\n\n\ndb = fsc.get_flask_sqlalchemy(_Base)\n\n\nclass NewModel(db.Model):\n    id: sa_orm.Mapped[int] = sa_orm.mapped_column(primary_key=True)\n    name: sa_orm.Mapped[str] = sa_orm.mapped_column()\n\n\nif __name__ == \"__main__\":\n    import os\n    import flask\n\n    app = flask.Flask(__name__, instance_path=os.path.abspath(\"./instance\"))\n    app.config.update({\"SQLALCHEMY_DATABASE_URI\": \"sqlite:///main.db\"})\n    db.init_app(app)\n\n    with app.app_context():\n        db.create_all()\n\n        # Indeed, flask_sqlalchemy has a type hint issue until `3.1.x`.\n        # But it does not cause issues in run time. See\n        # https://github.com/pallets-eco/flask-sqlalchemy/issues/1312\n        db.session.add(NewModel(name=\"new\"))\n        db.session.commit()\n\n        model = db.session.scalar(sa.select(NewModel))\n        print(model.id, model.name) if model is not None else print(\"NOT FOUND.\")\n```\n\nThe magic happens if you run the first example with only `flask-sqlalchemy` installed and the second example with only `flask-sqlalchemy-lite` installed.\n\nCompared to the above minimal examples, we also provided a `usage.py` file and example applications in the `examples/` folder. Check them to view more details.\n\n\u003e [!TIP]\n\u003e To run the demos in `examples`, you need to install the optional dependencies by\n\u003e ```sh\n\u003e python -m pip install flask-sqlalchemy-compat[example,backends]\n\u003e ```\n\n## 3. Documentation\n\nCheck the documentation to find more details about the examples and APIs.\n\nhttps://cainmagi.github.io/flask-sqlalchemy-compat/\n\n## 4. Contributing\n\nSee [CONTRIBUTING.md :book:][link-contributing]\n\n## 5. Changelog\n\nSee [Changelog.md :book:][link-changelog]\n\n[tool-git]:https://git-scm.com/downloads\n\n[link-contributing]:https://github.com/cainmagi/flask-sqlalchemy-compat/blob/main/CONTRIBUTING.md\n[link-changelog]:https://github.com/cainmagi/flask-sqlalchemy-compat/blob/main/Changelog.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcainmagi%2Fflask-sqlalchemy-compat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcainmagi%2Fflask-sqlalchemy-compat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcainmagi%2Fflask-sqlalchemy-compat/lists"}