{"id":13806643,"url":"https://github.com/tarsil/saffier","last_synced_at":"2026-03-08T13:02:47.857Z","repository":{"id":67534794,"uuid":"602231431","full_name":"tarsil/saffier","owner":"tarsil","description":"The only ORM that you will ever need for python.","archived":false,"fork":false,"pushed_at":"2024-10-15T09:39:30.000Z","size":1167,"stargazers_count":59,"open_issues_count":7,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-19T10:26:02.212Z","etag":null,"topics":["asyncio","database","mysql","orm","orm-framework","orm-model","postgres","postgresql","pydantic","python","python3","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"https://saffier.tarsild.io","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/tarsil.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":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["tarsil"]}},"created_at":"2023-02-15T19:16:59.000Z","updated_at":"2024-10-17T17:08:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"c981a2a9-fd76-4e77-89b4-69cf80828e12","html_url":"https://github.com/tarsil/saffier","commit_stats":{"total_commits":435,"total_committers":7,"mean_commits":"62.142857142857146","dds":0.1471264367816092,"last_synced_commit":"f09838196467b27c720b3f86c830e2e88b2db2a8"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsil%2Fsaffier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsil%2Fsaffier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsil%2Fsaffier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsil%2Fsaffier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarsil","download_url":"https://codeload.github.com/tarsil/saffier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332612,"owners_count":20921853,"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","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":["asyncio","database","mysql","orm","orm-framework","orm-model","postgres","postgresql","pydantic","python","python3","sqlite","sqlite3"],"created_at":"2024-08-04T01:01:14.228Z","updated_at":"2026-03-08T13:02:47.851Z","avatar_url":"https://github.com/tarsil.png","language":"Python","readme":"# Saffier\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://saffier.tarsild.io\"\u003e\u003cimg src=\"https://res.cloudinary.com/dymmond/image/upload/v1675104815/Saffier/logo/logo_dowatx.png\" alt='Saffier'\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cem\u003e🚀 The only Async ORM you need. 🚀\u003c/em\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/tarsil/saffier/actions/workflows/test-suite.yml/badge.svg?event=push\u0026branch=main\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/tarsil/saffier/actions/workflows/test-suite.yml/badge.svg?event=push\u0026branch=main\" alt=\"Test Suite\"\u003e\n  \u003c/a\u003e\n\n\u003ca href=\"https://pypi.org/project/saffier\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/saffier?color=2334D058\u0026label=pypi%20package\" alt=\"Package version\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://pypi.org/project/saffier\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/pyversions/saffier.svg?color=2334D058\" alt=\"Supported Python versions\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Documentation**: [https://saffier.tarsild.io](https://saffier.tarsild.io) 📚\n\n**Source Code**: [https://github.com/tarsil/saffier](https://github.com/tarsil/saffier)\n\n**The official supported version is always the latest released**.\n\n---\n\n## Saffier 2.0+\n\nSaffier is currently revamped, powered up and ready to be more powerful and flexible, while maintaining the same familiar interface.\nThe new version will be released as **Saffier 2.0** and the versioning will grow from there. The supported version will always be the latest released,\nso if you are using Saffier, make sure to keep it updated to the latest version to get the best experience and all the new features.\n\nWhy this now? Saffier plays an important role in the ecosystem of tools I am building and I want to make sure it is the best it can be for everyone.\nThe new version will be more powerful, flexible and easier to use, while maintaining the same familiar interface.\n\nSaffier was never neglected, or at least intentionally neglected, but it was always a challenge to maintain\nit while also working on other projects and tools.\n\nThis will no longer be the case and Saffier will come to stay.\n\nSaffier is intentionally Python-native and ORM-focused.\nIt is designed to stay framework-agnostic, lightweight in validation concerns,\nand aligned with the developer ergonomics that made Saffier popular.\n\nNow, if you are interested in helping and maintaining Saffier, please don't hesitate to reach out and contribute, it is always welcome and appreciated.\n\n## Motivation\n\nAlmost every project, in one way or another uses one (or many) databases. An ORM is simply an mapping\nof the top of an existing database. ORM extends for Object Relational Mapping and bridges object-oriented\nprograms and relational databases.\n\nTwo of the most well known ORMs are from Django and SQLAlchemy. Both have their own strengths and\nweaknesses and specific use cases.\n\nThis ORM is built on the top of SQLAlchemy core and aims to simplify the way the setup and queries\nare done into a more common and familiar interface.\n\n## Before continuing\n\nSaffier is built for teams that want a direct SQLAlchemy-core-powered ORM workflow\nwithout introducing a Pydantic-centric architecture in the model layer.\n\n## Why this ORM\n\nWhen investigating for a project different types of ORMs and compared them to each other, for a lot\nof use cases, SQLAlchemyalways took the win but had an issue, the async support (which now there\nare a few solutions). While doing the research I came across [Encode ORM](https://www.encode.io/orm/).\n\nThe team is the same behind of Databases, Django Rest Framework, Starlette,\nhttpx and a lot more tools used by millions.\n\nThere was one issue though, although ORM was doing a great familiar interface with SQLAlchemy and\nproviding the async solution needed, it was, by the time of this writing, incomplete and they\neven stated that in the documentation and that is how **Saffier** was born.\n\nSaffier uses some of the same concepts of ORM from Encode but rewritten in **Pydantic** but not all.\n\n## Saffier\n\nSaffier is some sort of a fork from [Encode ORM](https://www.encode.io/orm/) but rewritten at its\ncore and with a complete set of tools with a familiar interface to work with.\nIf you are familiar with Django, then you came for a treat 😄.\n\nSaffier leverages the power of **Pydantic** for its fields while offering a friendly, familiar and\neasy to use interface.\n\nThis ORM was designed to be flexible and compatible with pretty much every ASGI framework, like\n[Esmerald](https://esmerald.dymmond.com), Starlette, FastAPI, Sanic, Quart... With simple pluggable\ndesign thanks to its origins.\n\n### Special notes\n\nSaffier couldn't exist without [Encode ORM](https://www.encode.io/orm/) and the continous work\ndone by the amazing team behind it. For that reason, thank you!\n\n## Features\n\nWhile adopting a familiar interface, it offers some cool and powerful features on the top of\nSQLAlchemy core.\n\n### Key features\n\n* **Model inheritance** - For those cases where you don't want to repeat yourself while maintaining\nintregity of the models.\n* **Abstract classes** - That's right! Sometimes you simply want a model that holds common fields\nthat doesn't need to created as a table in the database.\n* **Meta classes** - If you are familiar with Django, this is not new to you and Saffier offers this\nin the same fashion.\n* **Managers** - Versatility at its core, you can have separate managers for your models to optimise\nspecific queries and querysets at ease.\n* **Filters** - Filter by any field you want and need.\n* **Model operators** - Classic operations such as `update`, `get`, `get_or_none`, `bulk_create`,\n`bulk_update` and a lot more.\n* **Relationships made it easy** - Support for `OneToOne` and `ForeignKey` in the same Django style.\n* **Constraints** - Unique constraints through meta fields.\n* **Native test client** - We all know how hard it can be to setup that client for those tests you\nneed so we give you already one.\n* **Multi-tenancy** - Saffier supports multi-tenancy and even offers a possible solution to be used\nout of the box if you don't want to waste time.\n\nAnd a lot more you can do here.\n\n## Migrations\n\nSince **Saffier**, like [Encode ORM](https://www.encode.io/orm/), is built on the top of\n[SQLAlchemy core](https://docs.sqlalchemy.org/en/20/core/), it brings its own native migration\nsystem running on the top of [Alembic](https://alembic.sqlalchemy.org/en/latest/) but making it a\nlot easier to use and more pleasant for you.\n\nHave a look at the [migrations](https://saffier.tarsild.io/migrations.md) for more details.\n\n## Installation\n\nTo install Saffier, simply run:\n\n```shell\n$ pip install saffier\n```\n\nYou can pickup your favourite database driver by yourself or you can run:\n\n**Postgres**\n\n```shell\n$ pip install saffier[postgres]\n```\n\n**MySQL/MariaDB**\n\n```shell\n$ pip install saffier[mysql]\n```\n\n**SQLite**\n\n```shell\n$ pip install saffier[sqlite]\n```\n\n## Quick Start\n\nThe following is an example how to start with **Saffier** and more details and examples can be\nfound throughout the documentation.\n\n**Use** `ipython` **to run the following from the console, since it supports** `await`.\n\n```python\nimport saffier\nfrom saffier import Database, Registry\n\ndatabase = Database(\"sqlite:///db.sqlite\")\nmodels = Registry(database=database)\n\n\nclass User(saffier.Model):\n    \"\"\"\n    The User model to be created in the database as a table\n    If no name is provided the in Meta class, it will generate\n    a \"users\" table for you.\n    \"\"\"\n\n    id = saffier.IntegerField(primary_key=True)\n    is_active = saffier.BooleanField(default=False)\n\n    class Meta:\n        registry = models\n\n\n# Create the db and tables\n# Don't use this in production! Use Alembic or any tool to manage\n# The migrations for you\nawait models.create_all()\n\nawait User.query.create(is_active=False)\n\nuser = await User.query.get(id=1)\nprint(user)\n# User(id=1)\n\n```\n\nAs stated in the example, if no `tablename` is provided in the `Meta` class, Saffier automatically\ngenerates the name of the table for you by pluralising the class name.\n\n## Connect your application\n\nDo you want to have more complex structures and connect to your favourite framework? Have a look\nat [connections](https:/saffier.tarsild.io/connection.md) to understand how to do it properly.\n\n**Exciting!**\n\nIn the documentation we go deeper in explanations and examples, this was just to warm up. 😁\n","funding_links":["https://github.com/sponsors/tarsil"],"categories":["Third-Party Extensions"],"sub_categories":["Databases"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarsil%2Fsaffier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarsil%2Fsaffier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarsil%2Fsaffier/lists"}