Roadmap
See original GitHub issueI’ve been thinking about how best to mature Starlette as it becomes more and more capable for large-scale projects. The key thing I want the framework to focus on is low-complexity of the underlying stack.
Rather than have a monolithic application object, where we put all the functionality on, I’d like to see us focus on independent components. I think this is really important, because it makes it so much easier to understand the stack that you’re building on top of. Components are independently testable, can be understood in isolation, and can be swapped out or adapted more easily.
One example here is we currently have template_dirs
on the application instance. That makes it less clear what interactions the application instance might have with template dirs under the hood. Instead we should keep all the templating properly independent from other parts of the stack.
A related aspect of this is routing. Right now we promote the decorator style, which is convenient. I think we should move towards promoting a more explicit style made up of the actual BaseRoute
instances that the Router
class uses. The reason here is that it explicitly surfaces information about how the underlying stack function. If you want to implement an alternative to Route
, WebSocketRoute
, Mount
, Host
, it’s already more clear how you’d do that. Even the call stack that gets passed through is being made more explicit. “Look at this class implementation if you want to understand what’s happening here”.
Here’s a sketch of how a more explicit style would fit together:
settings.py
DEBUG = config(...)
DATABASE_URL = config(...)
resources.py
cache = Cache(...)
database = Database(...)
templates = Jinja2Templates(...)
routing.py
routes = [
Route(...),
Route(...),
WebSocketRoute(...),
Mount(...)
]
application.py
middleware = [
...
]
app = Starlette(routes=routes, middleware=...)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:51
- Comments:17 (11 by maintainers)
Top GitHub Comments
Did some sketching out today of what you need in order to start getting towards a rough Django-ish feature parity.
Notable bits missing at the moment…
orm
needs aModelRegistry
typesystem
doesn’t yet have any API forvalidate_all
, or for async validators.RedirectResponse
to take an endpoint name.request
not be strictly required inTemplateResponse
.request.parse()
function, that just handles whatever media type.Even now, it’s quite an imposing chunk of code.
Opinionated framework may help with stability and understand-ability BUT please do not take it too far. I really like what @tomchristie says about independent components, I think we can all agree on the benefits of that. Having clear philosophy on an open-source project will make it or break it. But too much opinion in terms of “how to use” for the end-user may not be the wisest and people will start forcing their projects into a particular pattern without much forethought. Making opinions optional is always best.
E.G. with Django’s “Apps” most people try to divvy up their project, but then run into issues where their
models.py
files are all interdependent and tightly coupled, views start needing to query models in different apps, etc. So the next thing they try is just putting everything into a single “App” and end up with monolithic files. Then within a single App try their own organization strategies before eventually re-implementing django’s “Apps” and run into the same problems they had in the first place. Eventually they realize they need to go back to django’s multiple apps, but out-source the coupling to the settings, a process essentially missing from the django docs.So it’s really important when giving opinions on “how to use” that you back it with philosophy and clear guidance, otherwise people waste too much time on “this is how it’s supposed to be done” instead of “what’s the best way to do this”.