https://github.com/elizabethsiegle/cf-python-worker-query-d1
Query a D1 Database with Cloudflare Workers in Python
https://github.com/elizabethsiegle/cf-python-worker-query-d1
cloudflare cloudflare-d1 cloudflare-worker cloudflare-workers cloudflare-workers-d1 cloudflare-workers-python python
Last synced: 8 months ago
JSON representation
Query a D1 Database with Cloudflare Workers in Python
- Host: GitHub
- URL: https://github.com/elizabethsiegle/cf-python-worker-query-d1
- Owner: elizabethsiegle
- Created: 2024-08-14T22:27:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-15T18:24:29.000Z (over 1 year ago)
- Last Synced: 2025-03-27T06:16:54.417Z (11 months ago)
- Topics: cloudflare, cloudflare-d1, cloudflare-worker, cloudflare-workers, cloudflare-workers-d1, cloudflare-workers-python, python
- Language: Python
- Homepage: https://d1-python-worker.cloudspacevn.workers.dev/
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Query a D1 Database with Cloudflare Workers in Python
1. Create a new Cloudflare Worker from the command line with `npm create cloudflare@latest`. When prompted, give your project a name, select `Hello World example`, `Hello World Worker template`, and `Python (beta)` when asked about language.
OR
1. `git clone https://github.com/cloudflare/python-workers-examples
cd python-workers-examples/01-hello
npx wrangler@latest dev`
3. Replace the boilerplate code in a `src/main.py` with this `src/main.py` code.
4. Download this `quotes.csv` file from https://www.kaggle.com/datasets/manann/quotes-500k?select=quotes.csv
5. Save it to the `data` folder here
6. Run `python3 data/csvtosql.py`
7. Create a new D1 database in your Cloudflare dashboard 
8. Import the new SQL file to D1 with `npx wrangler d1 execute {YOUR-DATABASE-NAME} --remote --file=data.sql`
9. Deploy your Worker with `npx wrangler@latest deploy`
10. Get a random quote from the database by visiting your deployed worker in the browser!