Skip to content
프로젝트

cloudflare/python-worker-hello-world

GitHub에서 보기

소개

Python hello world for Cloudflare Workers

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
기록 수집 중
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Python hello world for Cloudflare Workers

Your Python code in index.py, running on Cloudflare Workers.

In addition to Wrangler and npm, you will need to install Transcrypt, including Python 3.7 and virtualenv.

Wrangler

  • Clone repository (git clone https://github.com/cloudflare/python-worker-hello-world)
  • Run npm install
  • Update wrangler.toml with your project name, account_id, and route as required

Further documentation for Wrangler can be found here.

Transcrypt

Before building your project, you'll need to do one-time setup of Transcrypt. Assuming you have Python 3.7 and virtualenv installed per the linked instructions above, that setup on unix systems looks like the following (for windows see virtualenv docs):

cd projectname

virtualenv env

source env/bin/activate

pip install transcrypt

After that you can run Wrangler commands, such as wrangler publish to push your code to Cloudflare. If you exit virtualenv (deactivate) and return to the project directory later, you'll need to activate virtualenv (source env/bin/activate) but will not need to rerun the other installation commands.

If python3 is not Python 3.7 on your system, make sure you install it, create the virtualenv using the right version of Python, and edit webpack.config.js under command to specify the correct path to the Python 3.7 executable in the virtualenv directory. If you are using Windows, see this workaround for an issue with transcrypt-loader paths.

For more information on how Python translates to Javascript, see the Transcrypt docs. especially the module mechanism and aliases.

Because of aliases, for a KV namespace binding named KV you can use KV.put normally, but need to use KV.js_get instead of KV.get. For example, a handler using KV might look like:

def handleRequest(request):
    return KV.js_get('foo').then(
        lambda v: __new__(Response('Python Worker hello world! ' + v, {
        'headers' : { 'content-type' : 'text/plain' }
    })))

관련 프로젝트 살펴보기

불러오는 중…