Hi All 👋

I’m excited to share that the latest version of Robyn now includes dependency injections but with a unique syntax.

For those who might not be familiar, Robyn is a fast, asynchronous Python backend web framework that operates with a Rust runtime, combining the best of both worlds for efficient and robust web development.

Here’s a sample example to illustrate the new feature:

from robyn import Robyn, ALLOW\_CORS

app = Robyn(__file__)

GLOBAL_DEPENDENCY = "GLOBAL DEPENDENCY"
ROUTER_DEPENDENCY = "ROUTER DEPENDENCY"

app.inject(ROUTER_DEPENDENCY=ROUTER_DEPENDENCY)
app.inject_global(GLOBAL_DEPENDENCY=GLOBAL_DEPENDENCY)

@app.get("/sync/global_di")
def sync_global_di(request, router_dependencies, global_dependencies):
   return global_dependencies["GLOBAL_DEPENDENCY"]  

It was one of the most requested features, and I’m curious to hear what the community thinks about this new approach. Any feedback or thoughts are greatly appreciated!

And as usual, the project can be found at: https://github.com/sparckles/Robyn

  • DanCardin@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 months ago

    I think the tact that fastapi takes, i.e. foo: Annotated[x, Depends(dependency)] , is honestly the best mechanism I’ve seen (so much so that I’ve utilized something similar, in my own cli library)

    It keeps your function arguments agnostic to the dependency, retain typing ability, “easily” composes into nested dependencies, various other things.

    By contrast, I’m not especially a fan of this because the function argument name is hardcoded, the object presumably has no ability to type the dependencies, it’s unclear how nested dependencies would work, and it’s also unclear if/whether dependencies are resolved eagerly or on access

  • fediverser_bot@fediverser.communick.dev
    link
    fedilink
    arrow-up
    1
    ·
    11 months ago

    This post is an automated archive from a submission made on /r/python, powered by Fediverser software running on fediverser.communick.dev. Responses to this submission will not be seen by the original author until they claim ownership of their fediverser.communick.dev account. Please consider reaching out to them let them know about this post and help them migrate to Lemmy.

    Lemmy users: you are still very much encouraged to participate in the discussion. There are still many other subscribers on !python@fediverser.communick.dev that can benefit from your contribution and join in the conversation.

    Reddit users: you can also join the fediverse right away by getting by visiting https://fediverser-portal.communick.dev/. If you are looking for a Reddit alternative made for and by an independent community, check out Fediverser.