- Create a new Cloudflare Worker from the command line with
npm create cloudflare@latest
. When prompted, give your project a name, selectHello World example
,Hello World Worker template
, andPython (beta)
when asked about language.
OR
-
git clone https://github.com/cloudflare/python-workers-examples cd python-workers-examples/01-hello npx wrangler@latest dev
-
Replace the boilerplate code in a
src/main.py
with thissrc/main.py
code. -
Download this
quotes.csv
file from https://www.kaggle.com/datasets/manann/quotes-500k?select=quotes.csv -
Save it to the
data
folder here -
Run
python3 data/csvtosql.py
-
Import the new SQL file to D1 with
npx wrangler d1 execute {YOUR-DATABASE-NAME} --remote --file=data.sql
-
Deploy your Worker with
npx wrangler@latest deploy
-
Get a random quote from the database by visiting your deployed worker in the browser!