SQLAlchemy with Anvil Datagrid - small tutorial application

For the past year, I’ve been using anvil-app-server to build a medical registry for a state agency. It’s a good size project with over 30,000 lines of code and a database with ~1000 lines of schema definitions . The project required all PHI to be stored in MSSQL, so SQLAlchemy is used for database transactions.

Before we started the project, I wrote a quick tutorial to demonstrate how Anvil and SQLAlchemy could be used together for basic CRUD operations, with an Anvil Datagrid that auto-saves each cell as the user edits values. It doesn’t look like there are any other tutorial examples like this floating around, so thought maybe this could help anyone who’s considered using SQLAlchemy with Anvil UI:

Clone

Live Example

That live example connects to a Sqlite database which exists as an ephemeral file on the anvil.works file system, so it may disappear occasionally.

This project started quite a while back, so the tutorial example was created using the Anvil classic editor and is running in version 1.7.3 of anvil-app-server, with the default version 1.3.24 of SQLAlchemy (that was installed with it on anvil.works). To be clear, the project does not run on hosted anvil.works servers at all in production.

Please let me know if you have any questions about using Anvil with SQLAlchemy - we’ve had a great experience with it :slight_smile:

3 Likes