Title: open ended discussion: use of PEP 593 in the "model" ecosystem · Issue #229 · fastapi/sqlmodel · GitHub
Open Graph Title: open ended discussion: use of PEP 593 in the "model" ecosystem · Issue #229 · fastapi/sqlmodel
X Title: open ended discussion: use of PEP 593 in the "model" ecosystem · Issue #229 · fastapi/sqlmodel
Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I already searched in Google "How to X in...
Open Graph Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...
X Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated searc...
Opengraph URL: https://github.com/fastapi/sqlmodel/issues/229
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"open ended discussion: use of PEP 593 in the \"model\" ecosystem","articleBody":"### First Check\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\nSee description\r\n```\r\n\r\n\r\n### Description\r\n\r\nThis is a continuation of a discussion on Twitter: https://twitter.com/tiangolo/status/1484092599166287874\r\n\r\nI think the work in SQLModel is amazing, I can't even begin to comprehend how complex it is behind the scenes.\r\nOne thing I've been wondering about, not related to SQLModel in particular but rather to the general ecosystem of \"models\" in Python (classes with fields? not sure what the technical term is here. I'm referring to dataclasses, Pydantic, SQLAlchemy, Piccolo, etc.) is if we could use PEP 593's `Annotated` to increase composability between these libraries.\r\n\r\nMost of these libraries use some sort of marker as a default value on fields to include metadata:\r\n\r\n```python\r\nclass Hero(SQLModel, table=True):\r\n id: Optional[int] = Field(default=None, primary_key=True)\r\n```\r\n\r\nI'm only using SQLModel as an example here, but `Field` could be Pydantic's `Field`, SQLAlchemy's `Column`, dataclasses' `field`, etc.\r\n\r\nThe issue here is that `Field` is only valid in the context ofSQLModel (or Pydantic or SQLAlchemy or whatever particular library). And it has to contain information for Pydantic (like JSON schema examples) as well as SQLAlchemy (primary keys, etc.).\r\n\r\nUsing `Annotated` this could look like:\r\n\r\n```python\r\nclass Hero(SQLModel, table=True):\r\n id: Annotated[Optional[int], Field(examples=....), Column(primary_key=True)] = None\r\n```\r\n\r\nIn other words, you can have any number of markers you want, and the libraries that use these markers can just ignore markers they don't recognize.\r\n\r\nPossibly even more difficult, if we could move away from base classes with meta classes that would improve composability even further. Think `from pydantic import to_json; to_json(SomeModel)` instead of having Pydantic create `SomeModel.json`. I think that's a totally different topic though.\r\n\r\nI'm not sure if this solves any problems, but I thought it's an interesting idea worth sharing.\r\n\r\n### Operating System\r\n\r\nLinux\r\n\r\n### Operating System Details\r\n\r\n_No response_\r\n\r\n### SQLModel Version\r\n\r\nN/A\r\n\r\n### Python Version\r\n\r\nN/A\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/adriangb","@type":"Person","name":"adriangb"},"datePublished":"2022-01-20T17:04:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/229/sqlmodel/issues/229"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0df7fe55-ec07-772e-b0db-3d255d8a60b5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 878C:1793BD:1AA40BC:242D629:6A62F2C9 |
| html-safe-nonce | 54585b418ae5e835854b4a31de72b7be7a623a7f8eb06168ed3ffaff22c74c22 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzhDOjE3OTNCRDoxQUE0MEJDOjI0MkQ2Mjk6NkE2MkYyQzkiLCJ2aXNpdG9yX2lkIjoiMTgwMzYwNjk4MTU2MTQ3OTg4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 04bc3ed29e013ce5338025e71185b914ff5c590d442ec264db9e33f21325f6bd |
| hovercard-subject-tag | issue:1109551877 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/229/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b723dba82ce84b7cbc15fa2840ea75aa9aa7f6f86cbe6bae49c34a90b82c5194/fastapi/sqlmodel/issues/229 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b723dba82ce84b7cbc15fa2840ea75aa9aa7f6f86cbe6bae49c34a90b82c5194/fastapi/sqlmodel/issues/229 |
| og:image:alt | First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adriangb |
| hostname | github.com |
| expected-hostname | github.com |
| None | b415018e190e73858133ddcaa36acce7b3f3572fe54dda84bd3b21a6ec714c30 |
| turbo-cache-control | no-preview |
| go-import | github.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git |
| octolytics-dimension-user_id | 156354296 |
| octolytics-dimension-user_login | fastapi |
| octolytics-dimension-repository_id | 399495186 |
| octolytics-dimension-repository_nwo | fastapi/sqlmodel |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 399495186 |
| octolytics-dimension-repository_network_root_nwo | fastapi/sqlmodel |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 22f98521e99f504294ab0812b66104d50eb75a70 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width