9 ms·
SQLAlchemy 2.0 Released
- oblio 4y agoDoes it fully support types? Edit: Oh, it seems to, that's big. For comparison, Hibernate, the Java mammoth ORM, as far as I know, never fully moved to Java 5 generics (released 18 years ago). Also dataclasses and enums. Also big, since there used to be a lot of duplication in configuration, SQLAlchemy doing its thing and the rest of the codebase just using now standard Python 3 features. Cool!
- luhn 4y agoNot only are the ORM objects typed, the query results are typed too. Last time I checked on 2.0 progress there wasn't a feasible way to implement this, so I'm thrilled to see that it made the release. # (variable) stmt: Select[Tuple[int, str]] stmt = select(User.id, User.name) with Session(e) as sess: for row in sess.execute(stmt): # (variable) row: Row[Tuple[int, str]] print(row) # (variable) users: Sequence[User] users = sess.scalars(select(User)).all() # (variable) users_legacy: List[User] users_legacy = sess.query(User).all() https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#typing-is-supported-from-step-3-onwards https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html...
- vladkovalev 4y agoFantastic, been waiting for this!
- wendyshu 4y agoIncreased static type coverage: https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#sql-expression-typing-examples https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html...
- akprasad 4y agoCongratulations on the release. I've been a happy user of SQLAlchemy for over a decade, and I'm looking forward to giving this version a spin.
- trevor-e 4y agoSorry for detracting from the release news but SQLAlchemy has to have the least helpful website of any major library I can think of. I'm trying to find basic 101 code examples and it's just one wall of text after another. I found how to cite SQLAlchemy in a research paper and have yet to find a single code example.
- airocker 4y agoI generally try StackOverflow/Google, then documentation and then discussion issues on SQLAlchemy. IT has worked well for me.
- akprasad 4y agoUnder the Current Releases section, click the docs link then ORM Quick Start. But it's tough to find at a glance.
- epgui 4y agoCheck out pugsql, we switched from SQLAlchemy to that because the former was overkill, and way too complex.
- b1ue64 4y agopeewee is also pretty good
- artemisart 4y agoI find ORM models useful for type checking and migrations, what is your experience for this with pugsql?
- airocker 4y agoI was just working on sqlalchemy. zzzeek's help if you get stuck somewhere is outstanding. Async is a godsent feature for us.
- wendyshu 4y agoOut of curiosity, what's the benefit of async for you?
- airocker 4y agoAsync sqlalchemy is required if we want to use an async appserver(tornado). We can serve a lot more requests per second with async. Otherwise, tornado was sync and could only serve one request synchronously at one time.
- wendyshu 4y agoThanks:)
- geenat 4y agoNon-blocking I/O is essential for high throughput, but high latency internet native databases such CockroachDB.
- bratao 4y agoI learned the hard way that I need to always use SQLAlchemy. I used other Python ORMs before and has been bitten hard with random bugs.
- habitue 4y agoYeah, ORMs are ten thousand edge cases, it really lays to use a battle hardened one that has been lovingly maintained and improved constantly for over a decade. Hats off to Mike, most projects that are this age are decrepit and you have kept it fresh.
- deaddodo 4y agoI will always stand behind SQLAlchemy being one of the best designed ORMs around. It generates some of the best backend SQL for the chosen dialect and it’s separation behind low level “core” concepts and high level ORM concepts makes for the cleanest separation of concerns. Even if it can’t generate the best SQL for you, it’s bog-simple to fiddle with the core components to hint it in the proper direction.
- jbellis 4y agoCongratulations!
- zzzeek 4y agoI would urge people who have had issues with the documentation to give the 2.0 documentation a try. Many aspects of it have been completely rewritten, both to correctly describe things in terms of the new APIs as well as to modernize a lot of old documentation that was written many years ago. First off, SQLAlchemy's docs are pretty easy to get to, for a direct link just go to: https://docs.sqlalchemy.org/ https://docs.sqlalchemy.org/ It's an esoteric URL I know! ;) from there, docs that are new include: - the Quickstart, so one can see in one quick page what SQLAlchemy usually looks like: https://docs.sqlalchemy.org/en/20/orm/quickstart.html https://docs.sqlalchemy.org/en/20/orm/quickstart.html - the Unified Tutorial, which is a dive into basically every important concept across Core / ORM : https://docs.sqlalchemy.org/en/20/tutorial/index.html https://docs.sqlalchemy.org/en/20/tutorial/index.html - the ORM Querying guide, which is a "how to" for a full range of SQL generation: https://docs.sqlalchemy.org/en/20/orm/queryguide/index.html https://docs.sqlalchemy.org/en/20/orm/queryguide/index.html it's still a lot to read of course but part of the idea of SQLAlchemy 2.0 was to create a straighter and more consistent narrative, while it continues to take on a very broad-based problem space. If you compare the docs to those of like, PostgreSQL or MySQL, those docs have a lot of sections and text too (vastly more). It's a big library.
- mixmastamyk 4y agoGreat tool. I think this is why folks have trouble finding the docs: Whole entire site is docs everywhere, including home page. Links to "docs" are tiny on the home page. Main menu calls them "library" instead of docs, why? Majority of the stuff is focused on migration rather than new users. These two should be separated into separate tracks immediately. There is an attempt, but it gets lost somehow. Also the release page linked here and "what's new in 2.0" go straight into the deep end, "inside baseball" style. These kind of pages should be very light. Tons of history-I'm personally not interested when trying to get something done. Unsolicited advice, move that into another blog post. ;-)
- zzzeek 4y agoThe link I posted here is the blog post. That's why it's historical and chatty, it's the blog post.
- siddboots 4y agoIt’s honestly something of a marvel to see a big ol’ framework like SQLAlchemy successfully manage these big structural api changes. The changes that have lead up to v1.4 and v2.0 have been very significant improvements to the user interface, and have kept the library up to date with the language in a way that is rare to see for a code base of such complexity. Also the new unified bulk insert interface is a big win for my ETL workflows. Hats of to everyone be involved!
- kerkeslager 4y agoSQLAlchemy's lightweight SQL wrapping was a revelation when I came across it, but I've come to rely a lot on Django's migration tooling, enough so to choose Django for projects. What do people using SQLAlchemy use for migrations?
- deaddodo 4y agoAlembic is the most common tool paired with SQLAlchemy.
- remram 4y agoAlembic is great. It will generate most schema changes from your updated models' code. I even use it programmatically in one app, to automatically migrate the SQLite database on the user's machine, and it has been extremely reliable.
- kerkeslager 4y agoI tried Alembic a long time ago, and it was a bit unstable then, but it was long enough ago that I seem to remember it being new, so maybe it's fixed up now. I'll give it another look.
- v3ss0n 4y agoAlembic
- robertlagrant 4y agoI just asked ChatGPT "How can I migrate database structures using SQLAlchemy?" and it gave an amazing answer. Alembic with examples.
- v3ss0n 4y agoFor a decade I avoided sqlalchemy, we finally got to use it last year and found it quite overwhelmingly complex and 1.4 documentation is messy. We had to use mixed styles. I checked unified doc and it had improved but , still wall of texts.. quite hard to read. Readability count's.
- whoopdeepoo 4y agoWhat do you use instead?
- v3ss0n 4y agoNow we're using Django for current project. But for new project we planned to use Starlite framework so we are still deciding 1. PicoloORM 2. Sqlalchemy 2.x And now finding sqlalchemy 2.0 still way too complicated
- gkmcd 4y agoHave you looked at peewee? It might be just what you're looking for. http://docs.peewee-orm.com/ http://docs.peewee-orm.com/
- thisismyswamp 4y agoAbsolutely agree, coming from the Node.js world documentation for Python packages (especially more established ones) is largely unapproachable, wording is unnecessarily obtuse and descriptions go on for too long. Code is presented in walls instead of being elegantly interspersed with short descriptions.
- whoopdeepoo 4y agoIncredible work, the best python database tool just got even better!
- kh1 4y agoIf you use pandas with SQLAlchemy, you should be aware that pandas might not be fully compatible with SQLAlchemy 2.0 yet. Some github issues: https://github.com/pandas-dev/pandas/issues/40686 https://github.com/pandas-dev/pandas/issues/40686 https://github.com/pandas-dev/pandas/issues/40460 https://github.com/pandas-dev/pandas/issues/40460 I'm not actively following how compatible pandas has become, but you should absolutely test your code if you want to upgrade to 2.0.
- westurner 4y agoFrom https://docs.sqlalchemy.org/en/20/dialects/ https://docs.sqlalchemy.org/en/20/dialects/ : > Currently maintained external dialect projects for SQLAlchemy include: [...] Is there a list of async [SQLA] DB adapters? The SQLAlchemy 2.0 Release Docs: https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.html https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.htm...
- geenat 4y agoWall of text. Less is more. Non-blocking I/O is wonderful news though, especially for high throughput yet high latency internet native databases such CockroachDB.
- remram 4y ago"internet native" is such a BS term. How has the rest of the internet survived this long, without their "native" tool...
- v3ss0n 4y agoI would request an experience sqla developer to write a blog post, tutorial or even a paid course for new sqla, doing general queries and necessary db operation, using 2.0 specific, best ORM way of doing things ( only one ORM style). And it should become default go-to doc for every new comers
- toinbis 4y agoLove the fact that Release notes (https://www.sqlalchemy.org/blog/2023/01/26/sqlalchemy-2.0.0-released/ https://www.sqlalchemy.org/blog/2023/01/26/sqlalchemy-2.0.0-...) give decent credits to SQLModel (https://sqlmodel.tiangolo.com/ https://sqlmodel.tiangolo.com/) for some of the typing innovations.
- Dowwie 4y agoCan someone share a summary as to what the caching strategy is and how it contributed to such gains?
- wpwpwpw 4y agojust want to thank the developers and community for their amazing effort. i just started webdev in python (which i did not previously used) and sqlalchemy's docs are amazing. again, thank you!
- aflukasz 4y agoCongratulations! Given how popular SQLAlchemy is, I wonder how many projects are going to wake up on Monday with failing tests (or production) due to not pinning versions and ignoring deprecation warnings...
- thisismyswamp 4y agoIt doesn't matter how good a library is, if care is not taken to make the documentation clean, accessible, elegant, concise, its legs are cut off from the start. Documentation authors should get out of their own heads while writing, and try as hard as possible to attain the perspective of a complete newcomer who will have no idea why a library needed to be split into Core and ORM in the first place.