Python: Deploying your Python code to production
This documentation is part of the Creating a REST API guide. You can view the complete guide here: How to create a REST API using Flask.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Python cloud solution that provides a host of benefits, including:
- Deploy your application in seconds with a simple
git push.- Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
- Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
- Get optimal performance and robust security thanks to a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's Python cloud hosting solution!
The simplest way to deploy your Python project is to use the Stackhero Python cloud hosting service. Key features include:
- Deployment with a simple
git push - Customizable domain with automatic TLS certificate management (HTTPS)
- Runs on a private and dedicated VM for maximum security
- Supports HTTP/2, TLS 1.3 (HTTPS), WebSockets, GZIP & Brotli compression, ETag, and TCP/UDP port access
Configuring the "Stackhero for Python" service
To deploy your code to Stackhero, follow these steps:
-
Retrieve your public key using:
cat ~/.ssh/id_*.pub -
In the Stackhero dashboard, go to your "Stackhero for Python" service and click the "Configure" button.
-
Copy the public key from the first step and paste it into the "SSH public keys" or "Key" field.
-
Validate the configuration by clicking the "Validate" button at the bottom of the page.
"Stackhero for Python" public key configuration
Don't have SSH keys? Create them by running:
ssh-keygen -t ed25519
Finally, configure your repository to deploy to Stackhero. In your project folder, add a Git remote using the command provided in your Stackhero service (replace <XXXXXX> with your service's domain):
git remote add stackhero ssh://stackhero@<XXXXXX>.stackhero-network.com:222/project.git
Git remote command
Deploying to production
Once everything is configured, deploy your code to production with a single command:
git push stackhero main
Ensure you add and commit your changes before pushing your code to production. In Stackhero Code-Hero, you can quickly commit changes using the Command Palette (press
Ctrl+Shift+Pon Windows/Linux orCmd+Shift+Pon macOS and typeGit: Commit).
After deployment, visit your API URL at https://<XXXXXX>.stackhero-network.com/api/tasks (replace <XXXXXX> with your service's domain) to see your Flask API in action.