-
Notifications
You must be signed in to change notification settings - Fork 26
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
Suggestions for fastapi support #3
Comments
We have plans for an SDK to make things more pythonic. I think that would be the best place to improve the FastAPI ergonomics for bindings. Regarding ORM, I think it would make sense to try to support Sqlalchemy. Is that too opinionated? |
Pyodide already includes sqlalchemy. If we add raw socket support they should work very well together. |
If we want to make SQLAlchemy work with D1 then we'd need to implement a Dialect for it. If we add socket support then we can support hyperdrive in SQLAlchemy pretty much for free, and support hosted databases that way. But this won't work with D1.
Yeah, I'd really love to see us offering type definitions like we do for TypeScript for our APIs. It's already on our todo list. |
Agreed, wasn't sure what it was called, but Dialect is what I had in mind. Would be great to support both. |
As this issue discussion environment variable, I also have some confusion.
model = ChatOpenAI(model="gpt-3.5-turbo", temperature=0,openai_api_key=env.OPENAI_API_KEY)
async def on_fetch(request, env):
prompt = PromptTemplate.from_template("Complete the following sentence: I am a {profession} and ")
chain = prompt | model
res = await chain.ainvoke({"profession": "electrician"})
return Response.new(res.split(".")[0].strip())
|
Well we do have a way to get the async def on_fetch(request, env: Env):
... |
I may not express myself clearly, I want to get the env parameter outside of |
That is also needed for me.
I hope I get these env by os.getenv
…---Original---
From: "Peter ***@***.***>
Date: Tue, Apr 16, 2024 17:22 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [cloudflare/python-workers-examples] Suggestions for fastapisupport (Issue #3)
I may not express myself clearly, I want to get the env parameter outside of on_fetch is that possible?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
emmmm you are right.
we need a better way to get
…---Original---
From: "Hood ***@***.***>
Date: Tue, Apr 16, 2024 17:27 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [cloudflare/python-workers-examples] Suggestions for fastapisupport (Issue #3)
os.getenv requires all of the values to be strings, if we try to put anything else in there we get a type error. Since many of the bindings aren't strings, I don't think this is a good approach.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
how about the second question? |
I think initializing at top level is fine for most purposes. |
I often use FastAPI to build the backend of my applications, so I was excited to see that I can write code using Python and FastAPI with Cloudflare Workers. However, after using it, I don't feel as comfortable as before.
For example, if I want to access my D1 database, I need to define the function's parameters as
req: Request
and useenv = req.scope["env"]
to get theenv
. Doing so means FastAPI can't help me validate my parameters, which is one of the main advantages of using it. Additionally, the lack of type hints makes development harder for me.On top of that, the absence of an ORM for D1 makes it quite troublesome to use, do you have any plans to develop an ORM?
The text was updated successfully, but these errors were encountered: