Comments (17)
Awesome, thanks for the investigation and help!
from piccolo_api.
We did some work with the Starlite team to make sure
piccolo_admin
can be mounted withinstarlite
, so hopefully that's also the case for things likePiccoloCRUD
. 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.
@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.
@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.
@sinisaos Thanks for the info - that's useful to know. I'll have to play around with Starlite some more.
from piccolo_api.
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.
@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.
@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.
@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.
@sinisaos OK, cool - if you could change the template that would be great.
from piccolo_api.
@dantownsend No problem, I'll do it now.
from piccolo_api.
Also is there any interest in adding a StarliteWrapper then? Maybe I could help out here.
from piccolo_api.
@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.
@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.
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.
I'm using FastAPI for now, so I'm not looking into any Starlite work atm
from piccolo_api.
@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)
- Add link to source code from docs
- Fix Sphinx warning about missing blank line
- CockroachDB always uses Timestamptz (at UTC) as TImestamp, confuses migrator. HOT 9
- Fix bug with `Email` columns and `PiccoloCRUD.get_new`
- `PiccoloCRUD` should handle unique exceptions better
- "Unable to split hashed password" HOT 4
- Fix MyPy errors with latest FastAPI version HOT 1
- Add type annotation for `id` to `SessionsBase`
- Update `logging.getLogger()` to use `__name__` instead of `__file__` HOT 3
- Support async validator functions
- Python 3.11 support
- Extend `db_exception_handler` to handle not-null exceptions
- CRUD Endpoint POST response is a list HOT 9
- Feature Request: Instead of just exposing the crud endpoints, can it generate the actual methods in a file? HOT 2
- Be able to sort by multiple columns in `PiccoloCRUD`
- Add `allow_unauthenticated` to `JWTMiddleware`
- TypeError: __init__() got an unexpected keyword argument 'excluded_paths' HOT 5
- Feature to modify body and query_parameters in `PiccoloCRUD` HOT 8
- Fix code scanning alert - Unused global variable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piccolo_api.