-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Updates Python Workers examples to use new Python SDK API #18596
base: production
Are you sure you want to change the base?
Conversation
Deploying cloudflare-docs with Cloudflare Pages
|
|
||
if location: | ||
return Response.redirect(location, 301) | ||
|
||
# If request not in map, return the original request | ||
return fetch(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something that confused me while I was going through these examples: this line ends up creating an infinite loop of requests back to the worker. What's the intention behind this? Is there something I missed?
I changed it here to return a 404 as it seems to make most sense for this example, but there are other examples that use the same pattern. I left those largely alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://developers.cloudflare.com/workers/configuration/routing/custom-domains/#interaction-with-routes for an explanation, this change should probably be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. These examples should really call this pattern out. Getting an infinite loop on examples like this is really not a great dev experience when playing with these examples locally.
Maybe something for another PR
7df4a10
to
e662fd3
Compare
|
e662fd3
to
a938004
Compare
@@ -61,19 +61,21 @@ export default { | |||
</TabItem> <TabItem label="Python" icon="seti:python"> | |||
|
|||
```py | |||
from js import Response, fetch, Headers, JSON, Promise | |||
from cloudflare.workers import Response, fetch | |||
import asyncio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be deployed even when packages not enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the actual SDK documented? Showing what modules and methods are available on it?
The new Python SDK is now available in the latest version of Wrangler. It provides Python native implementations of classes like
Response
.This PR modifies most of our Python examples to use the new APIs in the SDK.