Greetings and encouragements #96
Replies: 1 comment 7 replies
-
Hi great to see you around here, and thank you for all of the kind words and background! You are right that a lot of recent developments in Python have come together to make this all more possible than it used to be, it's an exciting time to be working on these things.
I completely agree. Writing more user friendly docs and examples is something I'm keeping in mind, but frankly I just haven't had time to do it yet 😄
That's very exciting! The more feedback the better. If there are broken bits or pain points, please do report them. Fortunately Xpresso is at the point where changes are still possible and welcome. Since you mention you are using a hexagonal architecture, I will mention that one thing that has worked well for me is type my endpoints / dependencies with abstract classes / protocols and bind them in the aggregate root, which if you are willing to take control of the event loop can also be where you initialize your database connections and such, making lifespans somewhat redundant: https://xpresso-api.dev/latest/advanced/dependencies/composition-root/. If you do go this route, I'd be curious to know if you think there's a use case for initializing the Of course Xpresso can still support lifespans and such for more FastAPI like dependency injection (even some pretty out there use cases like binding stuff from within a lifespan, which can be used to avoid storing database connections in |
Beta Was this translation helpful? Give feedback.
-
Hi there,
Just popping over here to say I'm really digging what I'm seeing around here. :-)
Bit of background from me - In 2018-2019 I worked on Bocadillo. It was sort of a personal "learn OSS" experiment, but also a mostly serious ASGI framework. It's now retired, but my favorite part of it was working on the DI system. I don't think FastAPI was around back then, or maybe just starting. Bocadillo's DI system was inspired by pytest's fixtures, just like Xpresso's it seems. I also ended up extracting it in a library, although it had several design flaws. Xpresso seems to take a similar, but much better thought-out route. It also helps that the Python typing ecosystem has moved greatly since then —
Annotated
/ PEP 593 looks like an actual keystone! The Dependencies introduction with that HTTPX example is a joy to read.The overall focus on decoupling is very pleasant. This is something I always had trouble with in FastAPI. Pydantic and the DI system is tangled right into the framework, making it a bit harder to understand as well as override if needed.
For now I'd just say the verbiage in READMEs and docs might be a bit too technical. I feel like it's a usual road when resorting to DI, which comes with concepts or ideas that most Python developers might not be used to.
I might try to swap FastAPI for Xpresso in a project I'm working on, and see how it goes. For reference, I'm currently using FastAPI for the web layer + punq for DI. I do use FastAPI's DI, but only for web-level stuff, such as checking auth / permissions. For other DI, such as resolving a database dependency, I need an agnostic DI library because I use hexagonal architecture, which means the web layer is pushed to the edge of a system (inspired by DDD) that otherwise ignores it's being exposed via a web API. The fact that Xpresso uses a separate and web-agnostic
di
library makes me quite excited that if my architecture is right I might be able to swap FastAPI + punq for Xpress + di! Well, as an exercise and experiment, at least.Not really expecting any answer here, but thought I'd share this with you.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions