{"id":33196623,"url":"https://github.com/phelps-sg/py-frm","last_synced_at":"2026-01-16T06:32:46.075Z","repository":{"id":210397843,"uuid":"726464210","full_name":"phelps-sg/py-frm","owner":"phelps-sg","description":"Functional-relational mapping framework for Python","archived":false,"fork":false,"pushed_at":"2023-12-02T22:56:53.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-10T11:12:56.742Z","etag":null,"topics":["functional-relational-mapping","python","relational-databases"],"latest_commit_sha":null,"homepage":"","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/phelps-sg.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}},"created_at":"2023-12-02T13:31:39.000Z","updated_at":"2023-12-30T08:57:04.000Z","dependencies_parsed_at":"2024-01-18T15:57:00.810Z","dependency_job_id":"2d07746d-690d-4958-b6b4-13d65aaa7634","html_url":"https://github.com/phelps-sg/py-frm","commit_stats":null,"previous_names":["phelps-sg/py-frm"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/phelps-sg/py-frm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelps-sg%2Fpy-frm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelps-sg%2Fpy-frm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelps-sg%2Fpy-frm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelps-sg%2Fpy-frm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phelps-sg","download_url":"https://codeload.github.com/phelps-sg/py-frm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phelps-sg%2Fpy-frm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285543732,"owners_count":27189594,"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-11-21T02:00:06.175Z","response_time":61,"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":["functional-relational-mapping","python","relational-databases"],"created_at":"2025-11-16T08:00:27.637Z","updated_at":"2025-11-21T02:01:10.751Z","avatar_url":"https://github.com/phelps-sg.png","language":"Python","funding_links":[],"categories":["Awesome Functional Python"],"sub_categories":["Libraries"],"readme":"# py-frm\nThis repo illustrates a proof-of-concept type-safe functional-relational mapping framework for Python inspired by [Slick](https://scala-slick.org/doc/stable/introduction.html).  The idea is that we can work with relational databases as if we are working with Python collections and dataclasses.  Moreover we can use [mypy](https://www.mypy-lang.org/) to provide type-safety.  \n\nIf you would like to see this project turned into a fully capable production-ready SDK, please star this repository and consider contributing by submitting issues and PRs.\n\n## Illustrative end-user code\n\nOur database model is represented using Python dataclasses, e.g.:\n\n~~~python\nfrom dataclasses import dataclass, field\nfrom py_frm import sqlalchemy_model\n\n\n@sqlalchemy_model(table=\"students\")\n@dataclass\nclass Student:\n    student_id: int = field(metadata={\"primary_key\": True})\n    name: str\n\n\n@sqlalchemy_model(table=\"courses\")\n@dataclass\nclass Course:\n    course_id: int = field(metadata={\"primary_key\": True})\n    title: str\n    student_id: int = field(metadata={\"foreign_key\": (\"students\", \"student_id\")})\n~~~\n\nDatabase queries are written as type-annotated Python generators using generator comprehensions:\n\n~~~python\nfrom typing import Iterable, Generator, Tuple\n\n\ndef get_student_courses(\n    students: Iterable[Student], courses: Iterable[Course]\n) -\u003e Generator[Tuple[str, str], None, None]:\n    return (\n        (s.name, c.title)\n        for s in students\n        for c in courses\n        if s.student_id == c.student_id\n    )\n~~~\n\nThe above type-annotated function can be statically checked by [mypy](https://www.mypy-lang.org/), and is automatically mapped onto the corresponding SQL query:\n\n~~~sql\nSELECT students.name, courses.title \nFROM students, courses \nWHERE students.student_id = courses.student_id;\n~~~\n\nSee [the example](./example.py) for the complete runnable code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphelps-sg%2Fpy-frm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphelps-sg%2Fpy-frm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphelps-sg%2Fpy-frm/lists"}