Where Should I Host My Python Project?
So you have finished your Python project and want to share it with your friends and family, however, you don’t know where to start. Well this blog post should help you narrow down the options to find the best option for you and your project requirements.
Hosting your project can be the most exciting part when developing your project as you now can share your hard work and talent with everyone else; however, this can also be one of the most frustrating and sometimes complicated parts due to the number of options out there and complexity of hosting your project.
The first question you have to ask yourself is what type of project is it? Are you using a web framework, such as Django or Flask; Are you wanting your code to be scheduled to run automatically at a certain time of day; Are you using a graphical library such as PyGame or Turtle; Or are you just wanting to host a console (command line) application. Depending on how you answered this question depends on where you end up hosting your project.
Web framework hosting
This is the most common reason why you would probably be hosting a Python project. Web frameworks in Python, such as Django and Flask, are currently a very popular way to create small and large scalable data driven websites due to the simplicity in creating the website and the power of the Python programming language. This has resulted in a lot of hosting sites to support hosting Python web frameworks. Two of the most popular are PythonAnywhere and Heroku.
PythonAnywhere
PythonAnywhere is one of the most popular sites for hosting your Python project, especially for small personal projects, and there is a good reason for this. You can host, run, and code Python all in the cloud! Unlike many other hosting sites PythonAnywhere has a free tier for hosting. This is great when you don’t want to spend loads and just want to share it with friends and family. There are limitations with this, however, if you are not expecting your website to have a lot of traffic and don’t mind not being able to change your url this is a great starting place. You can upgrade with your needs later as your website grows in scale. One of the biggest advantages of using PythonAnywhere is the simplicity. You can start hosting your website and project in minutes not hours, this helps considerably with their quickstart installers for Django, web2py, Flask, and Bottle; however they support any WSGI web framework.
Heroku
Heroku is another great option for hosting Python web framework projects. It requires a bit more work to start hosting and requires you to be comfortable using the command line of your computer. This option also has a free option, just like PythonAnywhere, to help you get started and the price goes up depending on how much traffic you are expecting and more advanced functionality. One benefit of Heroku over PythonAnywhere is the ability to use websockets in your project, which is not able to be done in PythonAnywhere at the time of writing.
There are other Python web framework hosting sites; however, these are the two easiest and most popular ways. These web hosting sites take out all the hard work of hosting. You don’t have to worry about setting up a database and you can get help if something goes wrong. When your websites start growing you can quickly scale up easily without having to worry about any problems.
Scheduling a Python Script to run
Pythonanywhere
If you are wanting to schedule a Python Script to run at certain times of the day, hosting your script in the cloud might be the easiest option. The easiest place to do this is using PythonAnywhere. PythonAnywhere allows you to quickly set up a task to run the python script to run daily at a particular time of day, or for paying customers hourly at a particular number of minutes past the hour. It's rather like a simple version of Unix's cron utility. This allows you to quickly get your tasks scheduled and up and running.
heroku
Heroku is another way to schedule a python script to run. This is a bit more complicated to set up as it isn’t by default a feature of Heroku. You will have to add an add-on to your dyno. There are many add-ons available for this so you can just choose the best for you. One of the most advanced feature rich add-ons for this job is advanced-scheduler.
aws lambda functions
Another way to schedule a Python Script is using an AWS Lambda functions. AWS lambda functions allow you not only schedule a script at certain times of the day but also when a certain event occurs, such as an inbound HTTP POST comes in to API Gateway or a new file is uploaded to AWS S3. This will require a bit more work to set up, but might be beneficial if you want to do more with your Python script.
Hosting a graphical (Turtle, PyGame) or console based project
Trinket
The best way to host a graphical project, like Turtle or PyGame, or a console application is using Trinket. Trinket allows you to share code from any device and lets you run and write code in any browser, on any device. It works instantly, with no need to log in, download plugins, or install software. And you can easily share or embed the code with your changes when you're done. Both PyGame and Turtle projects can be hosted using Trinket. Once you have created your Trinket, you can easily share the project by sharing the link, or by embedding the Trinket in a website. This is a great way to add Python projects to your website, especially if you want to host games created with PyGame and requires very little work to set up! One downside to Trinket is there are a limited number of external modules that you can use which could limit more complex projects.
Here is an example of Trinket being embedded into a web page. This is also one of the projects we do in our Introductory Python Course!
Hopefully you now have been able to choose the best option for your needs and now can start hosting your exciting projects which you can share with everyone else!
Reference
https://img.stackshare.io/service/4940/logo300x300.png
https://www.brandeps.com/logo-download/H/Heroku-logo-vector-01.svg
https://www.factor-a.com/wp-content/uploads//2019/05/Dayparting_Ad_Scheduling_Amazon_Sponsored_Ads-e1563961091588.jpg
https://www.netclipart.com/pp/m/348-3487927_transparent-aws-lambda-icon.png
https://trinket-app-assets.trinket.io/logo/PNG/stacked/trinket-logo-notag-white.png
Author: Robert Nimmo