{"id":51268488,"url":"https://github.com/viperadnan-git/supabase-orm","last_synced_at":"2026-06-29T16:30:50.364Z","repository":{"id":357657101,"uuid":"1235915133","full_name":"viperadnan-git/supabase-orm","owner":"viperadnan-git","description":"Lightweight async ORM on top of supabase-py with Pydantic validation. Type-safe query builder, PostgREST embeds, FastAPI-ready with per-request RLS.","archived":false,"fork":false,"pushed_at":"2026-06-24T22:10:25.000Z","size":1240,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-25T00:05:58.629Z","etag":null,"topics":["async","asyncio","fastapi","orm","postgrest","pydantic","python","supabase"],"latest_commit_sha":null,"homepage":"https://supabase-orm.readthedocs.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/viperadnan-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"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":"2026-05-11T19:24:36.000Z","updated_at":"2026-06-24T22:09:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/viperadnan-git/supabase-orm","commit_stats":null,"previous_names":["viperadnan-git/supabase-orm"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/viperadnan-git/supabase-orm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viperadnan-git%2Fsupabase-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viperadnan-git%2Fsupabase-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viperadnan-git%2Fsupabase-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viperadnan-git%2Fsupabase-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viperadnan-git","download_url":"https://codeload.github.com/viperadnan-git/supabase-orm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viperadnan-git%2Fsupabase-orm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34935220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"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":["async","asyncio","fastapi","orm","postgrest","pydantic","python","supabase"],"created_at":"2026-06-29T16:30:47.575Z","updated_at":"2026-06-29T16:30:50.355Z","avatar_url":"https://github.com/viperadnan-git.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# supabase-orm\n\n### A lightweight, Pydantic-native ORM on top of `supabase-py` — async-first, sync mirror generated.\n\n**[Documentation](https://supabase-orm.readthedocs.io/)** · [Install](#install) · [Quick start](#quick-start) · [Sync mode](#sync-mode) · [Contributing](#contributing)\n\n\u003c/div\u003e\n\n---\n\n## Features\n\n- **Pydantic models are tables.** One class is your schema, validator, and query entry point — no separate DTO layer.\n- **Typed query builder.** `Model.query.eq(...).gte(...)` autocompletes; typos raise at call time, not server-side.\n- **Composable predicates.** `Pet.f.age \u003e= 5` builds a `Predicate`; combine with `|` / `\u0026` / `~`, pass to `.or_()` / `.not_()`.\n- **Declarative embeds.** Annotate `Annotated[Owner, Relation(...)]` — the right `select=` string + `!inner` / FK hints are inferred.\n- **Keyset iteration.** `async for pet in Pet.query.iter():` — constant-time per batch, race-safe under concurrent writes, any table size.\n- **Async + sync.** Async-first for FastAPI; a byte-for-byte sync mirror at `supabase_orm.sync` is generated via `unasync`.\n- **Typed RPC.** Call PostgREST functions with row validation, single-row, or scalar coercion in one line.\n- **Per-request RLS.** `use_client()` with a JWT-authenticated client in a FastAPI middleware — zero leakage between concurrent requests.\n- **Safe by default.** Unfiltered bulk `delete()` / `update()` raise unless you opt in explicitly.\n- **Battle-tested.** 500+ mock tests for the wire contract; 80+ integration tests against real Supabase.\n\n---\n\n## Install\n\n```bash\nuv add supabase-orm\n# or\npip install supabase-orm\n```\n\nRequires Python 3.11+, `supabase-py 2.30+`, `pydantic 2.13+`.\n\n---\n\n## Quick start\n\n```python\nfrom uuid import UUID\nfrom typing import Annotated\nfrom supabase_orm import SupabaseModel, Relation, lifespan\n\n\nclass Owner(SupabaseModel, table=\"owners\"):\n    id: UUID\n    email: str\n    is_active: bool\n\n\nclass Pet(SupabaseModel, table=\"pets\"):\n    id: UUID\n    name: str\n    species: str\n    adopted: bool\n    owner: Annotated[Owner, Relation(join=\"inner\")]\n\n\nasync with lifespan(SUPABASE_URL, SUPABASE_KEY):\n    # Chain-style query (sequential AND)\n    cats = await Pet.query.eq(\"species\", \"cat\").order_by(\"-created_at\").limit(10).all()\n\n    # Typed predicates (OR / NOT / boolean composition)\n    rescues = await Pet.query.or_(\n        Pet.f.species == \"cat\",\n        (Pet.f.species == \"dog\") \u0026 (Pet.f.adopted == False),\n    ).all()\n\n    # Writes\n    p = await Pet.create(name=\"Whiskers\", species=\"cat\", adopted=False)\n    p.name = \"Mr. Whiskers\"\n    await p.save()\n\n    # Stream every matching row, any table size\n    async for pet in Pet.query.eq(\"adopted\", False).iter():\n        await process(pet)\n\n    # Bulk update / delete (guards block unfiltered ops)\n    await Pet.query.eq(\"adopted\", False).update(adopted=True)\n```\n\nFull guide: **[https://supabase-orm.readthedocs.io](https://supabase-orm.readthedocs.io)** — models, predicates, embeds, lifecycle, RPC, extending.\n\n---\n\n## Sync mode\n\nSame model classes, same chain syntax, same predicates. Switch the import and drop `await` / `async`:\n\n```python\nfrom supabase import create_client\nfrom supabase_orm.sync import SupabaseModel, init, shutdown\n\nclass Pet(SupabaseModel, table=\"pets\"):\n    id: UUID\n    name: str\n    species: str\n\ninit(create_client(SUPABASE_URL, SUPABASE_KEY))\n\ncats = Pet.query.eq(\"species\", \"cat\").limit(10).all()\nfor p in Pet.query.eq(\"species\", \"cat\").iter():\n    process(p)\n\nshutdown()  # optional — process exit drains pools anyway\n```\n\nThe sync tree is generated from the async source — no second implementation to keep in sync.\n\n---\n\n## Contributing\n\n```bash\ngit clone https://github.com/viperadnan-git/supabase-orm\ncd supabase-orm\nuv sync --all-groups\nuv run pytest                # mock suite (always runs)\n```\n\n### Architecture\n\n- `src/supabase_orm/_async/` is the canonical implementation.\n- `src/supabase_orm/_sync/` is **generated** by `scripts/gen_sync.py` (`unasync`-based token rewrite + prose regex + skip-block directive).\n- Tests mirror the same layout: `tests/_async/` is the source, `tests/_sync/` is generated.\n- A pre-commit hook (`nizm`) auto-regenerates and stages the sync mirror whenever `_async/**/*.py` changes. CI also runs `python scripts/gen_sync.py --check` to fail on drift.\n\n#### Skip-block directive\n\nWrap async-only test code (e.g. concurrency tests using `asyncio.gather`) so the sync mirror omits it:\n\n```python\n# gen_sync: skip-block\nasync def test_async_only():\n    ...\n# gen_sync: end-skip\n```\n\n### Running tests\n\n```bash\nuv run pytest                      # mock only (default)\nuv run pytest -m integration       # live Supabase\n```\n\nIntegration tests need a Supabase project with the test schema. See [`tests/integration/README.md`](https://github.com/viperadnan-git/supabase-orm/blob/main/tests/integration/README.md).\n\n### Building docs locally\n\n```bash\nuv sync --group docs\nuv run mkdocs serve   # http://localhost:8000\n```\n\n---\n\n## License\n\nApache License 2.0 — see [LICENSE](https://github.com/viperadnan-git/supabase-orm/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviperadnan-git%2Fsupabase-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviperadnan-git%2Fsupabase-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviperadnan-git%2Fsupabase-orm/lists"}