How to write python workers?

I'm trying to learn how to write python workers because I really don't know much about JS so I better try with python. The examples I found are different and I think some stuff is not being explained.

For example, here in the examples page: https://developers.cloudflare.com/workers/languages/python/examples it says that we should import
Response
and other stuff from the
js
package, but there is no
js
package, or well, there is one but I don't think it's related, there is no Response in that package. Then if I go to this example https://github.com/cloudflare/python-worker-hello-world/blob/master/index.py there is an
addEventListener
which afaik is not part of python.

I'm trying to write the worker on python because I need to access environment variables and I don't quite understand how to do that in JS, but then again I don't know how to do that in python either.
In general, as far as I've understood, I should write an on_fetch() function and call other functions from there as that's the only part where I can actually access the environment variables, is this right?

If this is true then how do I make it so that the function/worker is not available publicly, I mean if my function is at /api/function then anyone that finds out about it can make a request to it and the environment variables will be exposed. I'm using the
functions
subdirectory to store the workers.
specifically what I'm want to write is a function to send mails to myself from the form data the worker receives, the logic is already done but how to access the environment variables is what I don't understand plus my concern about the public access of that function. Please help
Was this page helpful?