Pirx: skeleton and a contract for applications built with Starlette and 3rd party modules

Few days back on the Encode’s Gitter chat I’ve proposed idea for a library that would introduce higher level structure to the projects, establishing contract for 3rd party packages and 1st party apps to work together, but also provide some basic necessities for project development, such as management commands, cookie-cutter project template and commands.

Today I’ve got time to put together a repo demonstrating such library:

This repo puts together two things:

  • pirx: library’s code
  • myapp and manage.py: example project code

I imagine that Pirx would introduce new workflow for developers aiming to write ASGI apps. Those developers would be able to begin project by installing pirx, using pirx-start-project.py myproject to initialize bare-bones project from template. Next, they would install 3rd party libs adding features they’ll need in their project.

For example, if they plan to use database, they would install the ORM plugin, that would use orm, databases and savannah packages and add following features: database connectivity, discovery of models defined in plugins models modules, management commands for database migrations and usage of databases in tests. They would only have to write those models and update settings to include DATABASES entry.

If they wanted to add basic user auth system, they would then install other plugin, that uses orm plugin to store users in database, but introduces user model, password handling and token based auth.

Etc. Ect.

This approach enables limited scope of core package, that only has to handle following things:

  • plugin system
  • configuration loading
  • management commands
  • test running

Everything else would come from plugins, and plugins could tap into, build on and extend any of those 4 features, enabling a contract for Encode and 3rd party packages to follow and play together.

1 Like