GithubHelp home page GithubHelp logo

Starlite support about piccolo_api HOT 17 CLOSED

mastercoms avatar mastercoms commented on June 15, 2024
Starlite support

from piccolo_api.

Comments (17)

mastercoms avatar mastercoms commented on June 15, 2024 2

Awesome, thanks for the investigation and help!

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024 1

We did some work with the Starlite team to make sure piccolo_admin can be mounted within starlite, so hopefully that's also the case for things like PiccoloCRUD. Here's the issue about it: piccolo-orm/piccolo_admin#211

@dantownsend You're right. We can mount PiccoloCRUD just like Piccolo Admin and every PiccoloCRUD endpoint works.

from piccolo_admin.endpoints import create_admin
from piccolo_api.crud.endpoints import PiccoloCRUD

# mounting Piccolo Admin
@asgi("/admin/", is_mount=True)
async def admin(scope: "Scope", receive: "Receive", send: "Send") -> None:
    await create_admin(tables=APP_CONFIG.table_classes)(scope, receive, send)


# mounting PiccoloCRUD
@asgi("/tasks/", is_mount=True)
async def crud(scope: "Scope", receive: "Receive", send: "Send") -> None:
    await PiccoloCRUD(table=Task)(scope, receive, send)

app = Starlite(
    route_handlers=[admin, crud],
    ...
)

When I tried that, I noticed that the Starlite asgi template doesn't work as it should, because now Starlite has different imports. If you want I can update the Starlite Piccolo asgi template to work as expected.

from piccolo_api.

dantownsend avatar dantownsend commented on June 15, 2024 1

@mastercoms I haven't given it much thought, but it should be doable.

If you want to have a go, that would be great. I imagine the implementation will be very similar to FastAPIWrapper.

My main concerns are:

  • The Starlite API still seems to be evolving - hopefully we can build upon it without any major breaking changes in the future.
  • We've had problems in the past with supporting Starlite and FastAPI, because they sometimes depend on conflicting versions of Starlette. So if possible we should keep starlite as an optional dependency.

Having said that, I think it's OK.

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024 1

@dantownsend Yes, Starlite does not use Starlette as dependencies any more and that's one of the reasons why I think making a StarliteWrapper would be a big task (as well as the other reasons I wrote before). FastAPIWrapper and PiccoloCRUD are very convenient methods to get a lot with a little code, but in the case of Starlite I think it's much simpler to write your own queries. Here is an example I made to see how Piccolo and Starlite work together and I had no problems. I didn't even use PiccoloORMPlugin (which is basically a wrapper around create_pydantic_model so you can use tables directly as request and response model in endpoints) but directly used create_pydantic_model.

from piccolo_api.

dantownsend avatar dantownsend commented on June 15, 2024 1

@sinisaos Thanks for the info - that's useful to know. I'll have to play around with Starlite some more.

from piccolo_api.

dantownsend avatar dantownsend commented on June 15, 2024

Most of the stuff in piccolo_api is generic ASGI middleware / endpoints, so theoretically can be mounted inside starlite.

We did some work with the Starlite team to make sure piccolo_admin can be mounted within starlite, so hopefully that's also the case for things like PiccoloCRUD. Here's the issue about it: piccolo-orm/piccolo_admin#211

If there's any documentation or anything we can add to make the integration easier for users, I'm happy to add it.

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024

@mastercoms I think that would be too much work because PiccoloCrud and FastAPIWrapper are based on Starlette and FastAPI. Also Piccolo Admin is based on FastAPI. If you want to use Starlite, there is a Starlite Piccolo asgi template. I made some starter template with Starlite and Piccolo to see how it fits together and had no problems integrating Piccolo with Starlite.

from piccolo_api.

dantownsend avatar dantownsend commented on June 15, 2024

@sinisaos Thanks for checking that.

Did Starlite recently change their imports? We run a test in Piccolo to make sure the ASGI templates work, so maybe it's a recent thing?

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024

@dantownsend Yes, 5 days ago. Before everything was from starlite import StaticFilesConfig and now is
from starlite.config.static_files import StaticFilesConfig etc.

from piccolo_api.

dantownsend avatar dantownsend commented on June 15, 2024

@sinisaos OK, cool - if you could change the template that would be great.

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024

@dantownsend No problem, I'll do it now.

from piccolo_api.

mastercoms avatar mastercoms commented on June 15, 2024

Also is there any interest in adding a StarliteWrapper then? Maybe I could help out here.

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024

@mastercoms I agree with @dantownsend, but I think it's a big task because FastAPIWrapper depends on PiccoloCRUD which is based on Starlette, and Starlette has been removed as a dependency on Starlite since version 1.39.0 (in theory you first need to make Starlite-based PiccoloCRUD). If you still want to make StarliteWrapper (which is based on Starlette PiccoloCRUD), I think (not sure) it will probably be quite different than FastAPIWrapper because Starlite routing has different implementation than FastAPI. I think that would be a big task, but feel free to try that if you want.

from piccolo_api.

dantownsend avatar dantownsend commented on June 15, 2024

@sinisaos Interesting - I didn't realise Starlite no longer had Starlette as a dependency.

Since FastAPI and Starlette share the same request object, it makes FastAPIWrapper quite simple. But to make a StarliteWrapper work, it would have to convert a Starlite request object into a Starlette request object - not sure how straight forward that is.

from piccolo_api.

mastercoms avatar mastercoms commented on June 15, 2024

Yeah, that's actually what prompted me to make this, I saw that Starlette dependency and imports in the source, so I didn't know if it would be compatible.

from piccolo_api.

mastercoms avatar mastercoms commented on June 15, 2024

I'm using FastAPI for now, so I'm not looking into any Starlite work atm

from piccolo_api.

sinisaos avatar sinisaos commented on June 15, 2024

@mastercoms I think you should close this issue as this is unlikely to be implemented as we discussed before. Thanks.

from piccolo_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.