Is there an example of how to integrate piccolo into an existing fastapi application?
Is there an example of how to integrate piccolo into an existing fastapi application?
Something along the lines of the examples in the fastapi docs here and here.
I'm interested in trying the ORM out as it reminds me a lot of how EntityFramework operates in the .NET world, but right now it seems a lot of magic and black boxed and to require using one of the generators to put all the pieces into place. That's just my perception. Anyways, would love to see a clean and understandable example for how to put this into an existing fastapi app and use similarily to the ORMs already mentioned in the fastapi docs.
Thanks much - wg
Here's an example:
https://github.com/sinisaos/headless-forum-fastapi
It uses FastAPIWrapper, which is a Piccolo thing, and lets you build a CRUD endpoint without writing much code.
However, that is totally optional - you can just write your own FastAPI endpoints manually.
I totally agree with your point though - more example projects are definitely needed. I'm working on a tutorial, but the more the better.
Cool thanks.
Yah, I'm looking for something less magical (still getting my head around your library) ... something where I can define all my database models in a models.py, all my pydantic view models in a view_models.py, and a local database session object I can use via dependency injection wherever I like. The structure of my particular application is closer to the postgresql template available via fastapi.
Thanks again - wg
On Tue, Feb 9, 2021 at 9:24 AM Daniel Townsend [email protected] wrote:
Here's an example:
https://github.com/sinisaos/headless-forum-fastapi
It uses FastAPIWrapper, which is a Piccolo thing, and lets you build a CRUD endpoint without writing much code.
However, that is totally optional - you can just write your own FastAPI endpoints manually.
I totally agree with your point though - more example projects are definitely needed. I'm working on a tutorial, but the more the better.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/piccolo-orm/piccolo/issues/67#issuecomment-776103826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADNMBHF46JYWOAQJWBWN3S6FVUHANCNFSM4XLLLJMA .
If I'm able to pass my hurdles in #112, I'll be happy to do a write-up of a tutorial and publish an example. Leaving this comment here so I'll remember to check back and hold myself somewhat accountable :)
@heliumbrain Thanks, I'd really appreciate that. Let me know if I can help in any way.
I've started setting this up here: https://github.com/heliumbrain/fastapi-piccolo
Won't have a lot of time for it this week, but I'll try to squeeze in a few hours.
@heliumbrain Awesome, thanks for this!
@dantownsend. So I managed to get quite a lot of it up.. I think I found a nice balance between Piccolo magic and raw Starlette/Pydantic/FastAPI. Please let me know.
Still struggling with the auth tho, can't really wrap my head around how to inject it as a Dependency (a la FastAPI). Have a look at https://github.com/heliumbrain/fastapi-piccolo/blob/main/piccolo-fastapi/product/routers.py. With that, I can login to /admin and get my cookie. It then (seemingly) correctly authenticates against that. Any feedback to improve that is appreciated :)
@heliumbrain It's looking really good.
The way I use the Session auth is something like this:
app = FastAPI()
private_app = FastAPI()
@private_app.get('/')
def top_secret_endpoint(request: Request):
user = request.scope.get('user').id # request.user may also work
return JSONResponse({'secrets': 'abc123'})
from functools import partial
auth_middleware = partial(
AuthenticationMiddleware,
backend=SessionsAuthBackend(...),
)
app.mount(path="/private-stuff", app=auth_middleware(private_app))
I'm not sure how it would work as a FastAPI dependency - I need to look into it.
@dantownsend cool, thanks! I'll look in to it a bit more too
@dantownsend I'll be working a bit more on this the next few days. Hopefully I'll have a fully working example-repo and a demo up before the weekend. I'll let you know, would love to get your feedback when it's done