DEV Community

Cover image for Python SDK: The Release
Rain Leander for Temporal

Posted on • Originally published at temporal.io

Python SDK: The Release

Calling all Pythonistas, we have some good news. Your days of wanting to use Temporal capabilities out of the box, but having to work around it, are over! We are so excited to share that now, thanks to the release of our new Python SDK, it's never been easier to enable durable execution in a Python app. Durable execution systems run our code in a way that persists each step the code takes. If the process or container running the code dies, the code automatically continues running in another process with all state intact, including call stack and local variables.

Why did we create this SDK

Community is at the core of what and why we do what we do. This particular SDK started out as a community-driven one, building on top of our open source core. From there we found that a handful of universities were using it as well. We were so encouraged by the community momentum, we made Python a fully featured, officially supported language with an SDK written and maintained by Temporal. We are looking forward to continuing to iterate on this for our community and we hope to hear from you on how we can make it even better!

Installation

Prerequisites: You’ll need Go 1.18 or later to run our Temporalite server.

Temporalite

This distribution of Temporal runs as a single process with zero runtime dependencies.

git clone https://github.com/temporalio/temporalite.git
cd temporalite
go build ./cmd/temporalite
Enter fullscreen mode Exit fullscreen mode

Python

Install the temporalio package from PyPI.

If you’d prefer to isolate and install in a virtual environment, you can follow instructions in our README.

Setup

In a terminal tab, navigate to your “temporalite” directory and run the following command to start the Temporal Server and Web UI process. This will be what the Temporal SDK talks to in order to keep the state of your application.

temporalite start
Enter fullscreen mode Exit fullscreen mode

You should see a bunch of lines of text scroll by—this is the Temporal Server running. Come back and check this terminal tab as you run the app below, you’ll see a lot more information.
If you want to change your namespace, you can pass in a namespace parameter to the start command like this: --namespace=okayest-namespace-name-ever.

By default, Temporal Server will be running at 127.0.0.1:7233 and you can visit the Temporal Web UI at http://127.0.0.1:8233.

Basic Usage of Temporal and Python

Just like any other Python app, you can have an entire application in a single file, and there is a great “hello world”-esque example in our samples repo: hello_activity.py.

To run the example:

git clone https://github.com/temporalio/samples-python.git
cd samples-python
poetry run python hello/hello_activity.py
Enter fullscreen mode Exit fullscreen mode

You should get:

Result: Hello, World!
Enter fullscreen mode Exit fullscreen mode

And you should see the GreetingWorkflow execution in the Web UI.

Success is at your fingertips

Et voilà! You’re all set to achieve your hopes and dreams with Python. Temporal can be used in many different ways, to suit your application's needs. To help with that, we have a handful of sample applications, depending on what you’re looking for. These should give you an idea of what capabilities you have with Temporal.

You can also learn through reading our any of the following:

Either way, let us know how it goes! Building something cool? We’d love to hear about it! Our forum has a new Show & Tell section. If you want to share, we’ll send you some sweet swag. Have feedback on how we can do better? We want to know that too. Raise an issue in the SDK or samples repos, or send us an email (devrel@temporal.io).

Coming Soon

We are looking forward to building more things with you and are excited to be part of the bigger Python community! We have a lot of exciting things coming down the pipeline this year: updates, events, demos, and more! Some of you may have heard of a little event in the fall, Hacktoberfest, which will have some investment from us this year! So stay tuned, friends, and we’ll see you soon.

Check out the next blog post in this series: Diving into Workers and Workflows with Python.

Top comments (0)