Setup
Getting started with Stack in 5 minutes
Welcome to the Python setup guide. If you’re looking for guides for other frameworks, check out the Next.js SDK Setup, React SDK Setup, or the JavaScript SDK Setup.
Our recommended way to use Stack Auth with Python is with the REST API. It provides a fully documented way to interact with Stack Auth from any Python framework, including Flask, FastAPI, and Django.
For the purpose of this guide, we will use the requests
library to make HTTP requests to the Stack Auth API. If you haven’t already, you can install it in your environment with pip install requests
.
Create API keys
First, create an account on the Stack Auth dashboard, and copy your project ID, publishable client key, and secret server key into a safe place (eg. environment variables).
From there, you can access them in your Python code. You can then read them like this:
Retrieve the access tokens
If you’re building a backend server, most likely you’ll want to use the currently signed in user’s access token. Most normally, you would send this with all your requests to the backend in an HTTP header.
In Stack Auth’s JavaScript SDK, you can retrieve the access token from the stackClientApp
object. Then, you can use said access token to make requests to Stack Auth:
Next steps
Check out the REST API documentation to learn more about the available endpoints and how to use them in your Python application.