Docs

Build a Script

You can use py.space to write and run Python scripts.

Example: Which City is Warmer?

Here’s a script that uses an API to fetch the current temperature for three different cities, and tells you which one is warmer:

Here’s how you build it:

1. Create a Script widget

Go to your account’s homepage, and under “What do you want to build?”, click Script.

By default, the script will come with a little “Hello World” content. Delete that code, and copy-paste the code from the example above.

2. Add a Secret

We need to use an API key to fetch the weather. You can get one for free at weatherapi.com.

Click Secrets in the top-right of the widget editor, then choose Create a new secret. Call it api_key, then click the Edit button to set the value of the secret. Paste in your own API key.

3. Run it

Click Run in the bottom right of the widget to run your script and see its output!

4. Share it!

Click the toggle at the top of the widget to make it public on your py.space profile!

Because you’ve stored your API key in your widget’s secrets, you can share your code with the world and still keep your API key secret!


Do you still have questions?

Our Community Forum is full of helpful information and friendly experts.