IoC for configuration of Starlette projects
Project description
IoC for configuration of Starlette projects
IoC stands for "Inversion of Control", it offers an alternate way to configure Starlette projects, in the fashion of Django's INSTALLED_APPS.
Install
Install with pip:
pip install starlette-apps
Purpose
The purpose is to split up imports and configurations from your starlette ASGI declaration script as such:
import apps
project = apps.Project(
TIMEZONE='Europe/Paris',
APPS=[
'your_db_config',
'your_app',
],
)
app = project.starlette()
IoC Flow
Instanciating a Project will basically get the .app
attribute of each modulle
in APPS
, which you may define for example as such:
import apps
app = apps.App(
name='Some app',
middlewares=[
Middleware(YourMiddleware)
],
routes=[
Route('/pattern', YourView),
],
)
App
You may also define your App declaratively, for example if you want to override some methods:
class YourApp(apps.App):
def get_routes(self):
if self.project.mode == 'production':
return your_production_routes
elif self.project.mode in ('test', 'dev'):
return your_production_routes + your_debug_routes
def setup(self):
"""
Do something as soon as your app is imported.
Useful to setup things such as a database connection.
"""
def startup(self):
"""
This will be passed to starlette on_startup.
Useful to run migrations for example.
"""
Note that Project will not just build a list of get_routes()
results, instead
it will call App.get_mount()
which in turn will return a Mount
of the
result from get_routes()
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file starlette-apps-0.1.0.tar.gz
.
File metadata
- Download URL: starlette-apps-0.1.0.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df2944d492e52918d35d4687ef0971653160674ba4aecbc0945eabfd66060ec0 |
|
MD5 | b064de7fca3b17908eb09bafd1d41b83 |
|
BLAKE2b-256 | 5bfc7d5168562ae6a486a742f23d578dae59cce05a8f75c909062673704deec9 |