TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Python Cloudflare Workers

389 点作者 jasoncartwright大约 1 年前

24 条评论

syrusakbary大约 1 年前
This is awesome, I&#x27;m happy that Cloudflare is adding more attention into running Python via WebAssembly at the Edge.<p>I&#x27;ll try to summarize on how they got it running and what are the drawbacks that they have from their current approach (note: I have deep context on running Python with WebAssembly at the Edge as part of my work in Wasmer).<p>Cloudflare Workers are enabling Python at the Edge by using Pyodide [1] (Python compiled to WebAssembly via Emscripten). They bundled Pyodide into Workerd [2], and then use V8 snapshots [3] to try to accelerate startup times.<p>On their best case, cold starts of Python in Cloudflare Workers are about 1 second.<p>While this release is great as it allows them to measure the interest of running Python at the Edge, it has some drawbacks. So, what are those?<p><pre><code> * Being tied to use only one version of Python&#x2F;Pyodide (the one that Workerd embeds) * Package resolution is quite hacky and tied to workerd. Only precompiled &quot;native packages&quot; will be allowed to be used at runtime (eg. using a specific version of numpy will turn to be challenging) * Architecturally tied to the JS&#x2F;v8 world, which may show some challenges as they aim to reduce cold start times (in my opinion, it will be quite hard for them to achieve &lt;100ms startup time with their current architecture). </code></pre> In any case, I welcome this initiative with my open hands and look forward all the cool apps that people will now build with this!<p>[1] <a href="https:&#x2F;&#x2F;pyodide.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pyodide.org&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;workerd&#x2F;blob&#x2F;main&#x2F;docs&#x2F;pyodide.md">https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;workerd&#x2F;blob&#x2F;main&#x2F;docs&#x2F;pyodide...</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;workerd&#x2F;pull&#x2F;1875">https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;workerd&#x2F;pull&#x2F;1875</a><p>Edit: updated wording from &quot;proof of concept&quot; to &quot;release&quot; to reflect the clarification from the Cloudflare team
评论 #39907338 未加载
评论 #39964164 未加载
评论 #39907251 未加载
评论 #39909258 未加载
评论 #39907173 未加载
jatins大约 1 年前
Clouflare has a lot of great stuff for hosting and databases but I think they haven&#x27;t done a great job marketing themselves as developer platform which has lead to platforms like Vercel, Netlify taking significant mindshare.<p>Tangential: does Cloudflare provide container hosting service agnostic of language -- something like Google Cloud Run?
评论 #39906635 未加载
评论 #39907817 未加载
评论 #39911785 未加载
评论 #39907286 未加载
评论 #39906629 未加载
评论 #39913526 未加载
评论 #39906388 未加载
jasoncartwright大约 1 年前
I&#x27;ve played with JS workers on a Cloudflare-fronted site and found them to be easy to use and very quick. Would love to port the whole Django app behind the site over, using their D1 database too.
评论 #39906311 未加载
评论 #39906379 未加载
评论 #39906560 未加载
tyingq大约 1 年前
A performance comparison to a JS worker would be helpful. It does sound interesting, but also sounds potentially slow, given all the layers involved.<p>Not that I&#x27;m expecting parity, but knowing the rough tradeoff would be helpful.
评论 #39906937 未加载
评论 #39906104 未加载
harikb大约 1 年前
Is the choice of lzma to demonstrate isolation intentional or was it just a coincidence considering last week&#x27;s tech news...[1]<p>[1] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39865810">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39865810</a>
评论 #39907879 未加载
noman-land大约 1 年前
This is kind of a game changer for running AI stuff on Cloudflare. Been hoping for this for a while now.
评论 #39906395 未加载
评论 #39906731 未加载
fastball大约 1 年前
Tried this out today and it was great, was very quick to get up and running!<p>One question though – does anyone know how I can get my local dev environment to understand the libraries that are built-in to CFW&#x27;s Python implementation? e.g. there is an `asgi` library that I do not want my linter to flag as unknown, but as it only exists at runtime in the `on_fetch` handler (and isn&#x27;t actually present in my local dev machine, I couldn&#x27;t figure this out.
gregorymichael大约 1 年前
I’ve used CF Pages for static sites with great results and am intrigued by all their open-source-LLM-as-a-service offerings. Main issue preventing me from building more on CF is lack of Python support. Excited to try this out.
评论 #39906102 未加载
pelletier大约 1 年前
I&#x27;m curious to see how the limitation of using pyodide packages only will play out for non-trivial builds. Thinking of all the non-pure python code out there that need to be manually rebuilt to support a non-trivial production app.<p>Maybe Cloudflare&#x27;s adoption will help bring more packages into the fold, and if it&#x27;s an 80&#x2F;20 rule here, would be good enough.
评论 #39906711 未加载
adam_arthur大约 1 年前
I would like to see CloudFlare implement workers with WASM as the first class citizen, and a general purpose API not tied to JS workers.<p>Up until now you&#x27;ve been able to deploy WASM code (e.g. effectively can use any language), but it runs within a JS context, rather than natively.<p>Just a bit more overhead&#x2F;awkwardness in deployment. I believe eventually all services will be deployed directly to WASM (securitized) runtimes, rather than via containers, similar to how we moved from images -&gt; containers).<p>There&#x27;s very little benefit currently to trying to use something like Rust on the edge (in CF), because a lot of the perf advantage is negated by the overhead and startup times.<p>e.g. <a href="https:&#x2F;&#x2F;github.com&#x2F;WasmEdge&#x2F;WasmEdge">https:&#x2F;&#x2F;github.com&#x2F;WasmEdge&#x2F;WasmEdge</a>
neonsunset大约 1 年前
I with they added Azure Functions style workers using C# too, or AWS style lambdas using NativeAOT. Way lower runtime overhead and time to first response latency.<p>But C# is an underdog language in those lands, so it&#x27;s understandable.
评论 #39906888 未加载
jarpineh大约 1 年前
More development and users for Pyodide is great news. Especially that better serverless story for Python server frameworks.<p>I wonder if Jupyter can work in this stack? It is essentially JavaScript, but built for browser environment. Just the Python kernel might be worker compatible. It essentially has to do code evaluation which might a limitation as well. Should it work you could offload compute from browser or other HTTP clients to waster resources of worker environment. Direct access to databases would be better as well.
评论 #39907951 未加载
rodolphoarruda大约 1 年前
Interesting. HTMx -&gt; Python -&gt; SQlite all in Cloudflare. I was kind of waiting for this day.
alfor大约 1 年前
I don&#x27;t see how people will start using a completely new way python is running.<p>If you are just experimenting and having fun, sure. But would you bet your company or many many months of developpement on this? What happen if you get random bugs?<p>The advantage need to be extremely high to make it worth it. Maybe for specialized work that need to happen at the edge and then, why not use js instead that is the bedrock of this implementation?
评论 #39907497 未加载
评论 #39909314 未加载
devwastaken大约 1 年前
It compiles python to we assembly which then runs on their modified V8 runtime. We assembly is generally a non solution to any problem, especially not this one. While it is convenient it is a clear lack of engineering ability that they can&#x27;t implement a proper Python runtime.<p>The reasons to not use wasm are many - the tool chains for emscripten are not well documented, hacky, and we&#x27;re not built to the quality you&#x27;d expect from a compiler. After all it&#x27;s doing something nothing was designed for.<p>The performance will never be an improvement over a native engine, much of the context is lost in translation when compiling to wasm.
zinclozenge大约 1 年前
I&#x27;d be curious to see a direct performance comparison between their python and JS workers. Based on my own experience with pyodide, I&#x27;d wager there might be up to a 2x performance penalty.
iamcreasy大约 1 年前
As opposed to what the article says, urllib3 now has experimental support for browser as of January this year.<p>Source: <a href="https:&#x2F;&#x2F;github.com&#x2F;urllib3&#x2F;urllib3&#x2F;releases&#x2F;tag&#x2F;2.2.0">https:&#x2F;&#x2F;github.com&#x2F;urllib3&#x2F;urllib3&#x2F;releases&#x2F;tag&#x2F;2.2.0</a>
paddy_m大约 1 年前
Glad to see it includes numpy (and presumably pandas). Getting those to work in constrained serverless environments can be a huge pain.
pbamotra大约 1 年前
Interesting - supports FastAPI and Langchain too <a href="https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;workers&#x2F;languages&#x2F;python&#x2F;packages&#x2F;" rel="nofollow">https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;workers&#x2F;languages&#x2F;python&#x2F;p...</a>
anon373839大约 1 年前
With Pyodide getting some serious backing, is there a glimmer of hope that we could end up with Python as a real alternative to JavaScript in the frontend?
评论 #39912140 未加载
hdlothia大约 1 年前
Wow this is huge for llm and data engineering. Many of the best libraries are in Python
Terretta大约 1 年前
<i>&quot;This is about more than just making bindings to resources on Cloudflare more Pythonic though — it’s about compatibility with the ecosystem.&quot;</i><p>Someone might be getting editorial help from GPT-4.<p>&#x2F;&#x2F; Or a human might be getting fine-tuned interacting with LLMs, which I&#x27;ve noticed happening to me.
评论 #39912724 未加载
评论 #39911996 未加载
pjmlp大约 1 年前
Why anyone would like to slow down their requests using a full interpred implementation is behind me. Don&#x27;t be surprised by scalability issues.
评论 #39907382 未加载
ssijak大约 1 年前
Can we just get full node runtime? Cloudflare is amazing, but without a full node runtime, we (and most of the usual apps) can&#x27;t switch from things like Vercel&#x2F;Netlify to Cloudflare.
评论 #39907095 未加载