-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow spinning up a web server and JSON api? #16
Comments
It would also open up building SPAs and mobile apps |
Could possibly be done with something similar to how |
Yep! For example, it could discover data providers by type annotations (e.g. |
Been playing around with fastapi and pydantic a bit; feel like they might integrate nicely here -- especially if the NamedTuple/dataclasses can be converted into pydantic Models by inspecting the type hints; that would mean all the routes would generate dynamically. pydantic allows for NamedTuple-like model definitions to be automatically serialized/deserialized into JSON for APIs, FastAPI uses pydantic when creating routes, and also creates an OpenAPI spec/dashboard for all your routes, which would allow for easy testing/prototyping for free. Is just a thought, but if this is used, since the deserialization is also handled, perhaps this could enable Not high on my priority list, but will probably try and create a prototype soon. |
Nice! I've had pydantic on my todolist as well, e.g. I like the idea of nicer exceptions: https://pydantic-docs.helpmanual.io/#example My only worry from a quick glance was that it enforces inheriting from a |
Have a pretty decent prototype up, Flask correctly serializes all of my data (though I havent tried with dataframes and the like, but this calls https://github.com/seanbreckenridge/HPI_API After:
If you end up testing, let me know if you have any issues/suggestions Not sure if this should be merged into here/kept separate; linked to, I'm fine either way. Sidenote: Initially tried to use FastAPI, but since all of this is dynamic, it just feels like I'm fighting with its JSON encoder and its class-model based approach. Would have to do some serious metaprogramming/class generation /w runtime type inspection and it didn't seem worth it. Custom Encoders through its at that point, I'm getting none of the benefits of the types that pydantic gives me, so its not particularly worth to use it |
Whoa, this is awesome, well done! Very cool that it seems pretty compact.
Yeah.. I guess for now OK to keep in a separate repo and play around with it.. I guess in principle would be cool to keep decoupled if possible, although if it ends up being compact and generic enough, doesn't hurt to keep in the 'main' package, I guess. |
The only real 'dependencies' it has on HPI are in the discovery file, using core_config to check if modules are disabled (though thats not really needed, its just to avoid some import errors if you have modules disabled; if its not able to be imported it just assumes all are active), and the Otherwise it just uses |
@seanbreckenridge sorry for the delay, was busy with other stuff. Just properly checked it out and it's brilliant, worked flawlessly! I wanted to do a proper demo in an Observable notebook connected to HPI on my computer (via a proxy): https://observablehq.com/@karlicoss/hpi_meets_http However it turned out that I can't export static HTML in observable, and of course it can't request the data unless I keep the server running... So I just did a screenshot 🤷 Some potential ideas for the future:
|
CORS slipped my mind, added a flag to enable/disable it, is enabled by default.
Typically people will recommend to just use flask_cors, but I just added a hook.
havent done this before, will have to look into it Regarding pagination, I initially just went with limit/page since it seemed to be the easiest to implement for unknown data. All I'm really doing right now is calling iter on it.
I suppose the only issue with using the default Not saying it can't be done, I'm just at a loss other than like... storing a large sequence of hash values in memory leading up to the cursor and searching for that? Seems quite finicky, unsure. Perhaps the user has to specify an attribute on the object that acts as the hash key as a GET arg?
I don't think this has to interface with It would be nice if 'n most recent' sort/order_by results were cached, as one would probably be requesting the same route with different offsets/cursor -- Would be possible to save some sorted results in memory. None of these feel like great solutions though - it's difficult to draw a line in the sand and reason about what should be done for data returned from arbitrary HPI functions. |
This is more of a fun demonstration of what's it capable of, but could also help for integrating with other programming languages.
Should be fairly easy and with almost no boilerplate because namedtuples/dataclass map nicely into JSON.
The text was updated successfully, but these errors were encountered: