Starlette Bridge
🚀 The Starlette events bridge that you need. 🚀
Documentation: https://starlette-bridge.tarsild.io 📚
Source Code: https://github.com/tarsil/starlette-bridge
Motivation
Starlette has evolved and it will keep on growing. In the release 0.26+ it was announced the
on_startup and on_shutdown events would be removed in favour of the newly lifepsan and those
would be officially removed in the release 1.0.
The problem is the fact that there are a lof od packages out there still using the old ways of using the events and this change will introduce breaking changes.
This bridge will make sure that doesn't happen and you can still use the old form of using the
on_startup and on_shutdown without breaking the lifespan from Starlette.
What Starlette Bridge does for you is simple. It gets the on_startup and on_shutdown events
in the same fashion you could do before and internally generates the newly lifespan for starlette.
That simple. Keeping the old syntax intact and using the newly lifespan.
Installation
To install Starlette Bridge, simply run:
$ pip install starlette-bridge
How to use
This is actually very simple to do it. You don't need to do anything particularly difficult, in fact, you only need to update where your Starlette object comes from.
from starlette_bridge import Starlette
app = Starlette()
And that is pretty much it.
How does it work
Starlette bridge simply maps your on_startup and on_shutdown events and converts them into
the new lifespan async generator from Starlette.
This way you can continue to use your preferred way of assembling the events while maintaining the new structure required by Starlette for managing events.
on_event and add_event_handler
These two pieces of functionality are also supported by the bridge making sure that what you had in the past, still remains working as is without changing the syntax.
Let us see an example how it works. We will be using Starlette Bridge because already contains events we want to use.
on_startup/on_shutdown
Using the on_startup and on_shutdown.
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
app = Starlette(
on_startup=[database.connect],
on_shutdown=[database.disconnect],
)
Lifespan
You can, of course, use the lifespan as well.
from contextlib import asynccontextmanager
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
@asynccontextmanager
async def lifespan(app: Starlette):
# On startup
await database.connect()
yield
# On shutdown
await database.disconnect()
app = Starlette(lifespan=lifespan)
on_event and add_event_handler
As mentioned before, those two functionalities are also available.
on_event
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
app = Starlette()
@app.on_event("startup")
async def start_database():
await database.connect()
@app.on_event("shutdown")
async def close_database():
await database.disconnect()
add_event_handler
from saffier import Database, Registry
from starlette_bridge import Starlette
database = Database("sqlite:///db.sqlite")
models = Registry(database=database)
app = Starlette()
app.add_event_handler("startup", database.connect)
app.add_event_handler("shutdown", database.disconnect)
Notes
This is from the same author of Esmerald, Saffier and Asyncz. Have a look around those techologies as well 😄.
Metadata
Release files for starlette-bridge 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| starlette_bridge-0.3.0.tar.gz | 6.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| starlette_bridge-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / starlette_bridge-0.3.0.tar.gz
| Download URL | starlette_bridge-0.3.0.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba2ded31e27aaeede581d16499121b9f34a089a4bee5599738418ecc4f9ba30b
|
|
BLAKE2b-256 checksum How to use checksums |
9ad9d3d5f6b7aa78b7423d31dec30913f1bfb6dbed8ca96948b30dea1fb7f898
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / starlette_bridge-0.3.0-py3-none-any.whl
| Download URL | starlette_bridge-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2871b1cb81016223405c2176b7d4b2ccc3e6f56e2c4b6e6e2deb34642355e017
|
|
BLAKE2b-256 checksum How to use checksums |
a904032159a8f219369c72df6f8be11ba48fe2fba06a7d2349a2e482089d6e8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for starlette-bridge 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.