Search code examples
pythonserver

Python Read/write server


Hi I was wondering whether there is a server out there that lets me read and write to it a bit like how you can with .txt files. I also want to be able to access it from any computer with internet access. Being only a child, I don't really have the means to pay for an expensive one, so a free/cheap one would be preferable.

I want to use this to make chatrooms (for only me and my friends) or somewhere to store game high scores. So only 500mb is needed.

If so could you tell me how to use it? Thanks


Solution

  • There are alot of ways you can do this. I had found myself also once in such a situation where I needed a free way to store data online safely for my small needs in my applications.

    I had researched a bit, and the following seemed like possible solutions -:

    • Firebase-: There is a special python module called pyrebase that deals with the sending and receiving for data for firebase and it is developed by google, so its quite secure too. Another advantage is the fact that it is cross compatible with android and ios, also since android does use firebase and firebase was originally developed for android development and to provide database services for android only. The realtime database feature of this API can be used for your use case easily. The API though has some features free but not all. There is a monthly limit of how many requests you can send if you are using the free plan, but that limit is more than enough for programs that are being unofficially made for testing. Also note that it does limit you, to python and it's own API's capabilities. It though can help you with alot of server related stuff, without needing to set it all up from scratch.
    • Heroku + SocketStuff -: There also exists a service called heroku, which lets you set up your applications on cloud, so you do not need to have your own server set up for running your application, But unlike firebase it lets you customize everything, but it also means that the database has to be made by you and uploaded on heroku along with a python file that can act as a worker file and receive requests for data upload/transfer. Again, this is completely free till a limit, but I found myself comfortably being able to fit most of the programs in that limit, and having a single worker file would not cross that limit. The python file that will accept requests for data will need to use the socket library to do so. This way you will have a more pythonic and more deeper way to handle your data, since the python file is custom made unlike firebase that had built in APIs for data exchange. Also note the conclusion with this method is that it does increase the limits of your capabilities of what you can do with these servers but it also leaves most of the server files code stuff in your hands, which is good, but might be time consuming in some cases.
    • PythonAnywhere -: This is a cloud application hosting service specially designed for python related applications, so it will provide you a more user friendly and understandable interface. But some python features such as asynchronous stuff, does not really work properly in all cases, and it cannot be fixed as mentioned here in their forums. Also similar to heroku, you will have to setup your server side code yourself, and it does not have that handled for you. It also has a more strict limit, but it depends on the use case. It is again free for use till a certain limit above which you need to pay to use extra features or exceed the limits. Note it is less customizable than heroku, and also unlike firebase it probably won't support android that well, since android with python is not that common. But for a pythoner, it is a good starting destination.

    I personally started with using Firebase. Later I found out about Heroku and for me it seems a better option to use for some projects but not for all. I did really like the interface of python anywhere and how clear everything you need to setup is presented, but the fact it could not run asynchronous code was where I decided to switch.

    EDIT: Also as you mention that you want to store game high scores or chats of chatrooms, I suggest you use firebase since you point out its for you and your friends so it is basically for unofficial testing purposes and the documentation for the pyrebase module is short and easy enough to grasp(note that its provided in their github page only). The other two alternatives can be something you can use for other projects that require more code customization.

    To setup firebase you will need to go to firebase console first and setup a project there, then you will need to create the realtime database, and then go to project overview to get the details(refer to pyrebase docs to understand which details you will need, direct link here) that you will need to enter in your python file to setup a connection.

    The green mark shows where you need to navigate to get to the project details and the red mark shows the place to navigate to setup the realtime database (NOTE: This is once you have setup your project, also you will require a gmail account for this.)

    To use the database service you will also need to intialize an object for it as mentioned here.

    I will suggest you directly take a look at this part of the pyrebase docs that discuss about data saving and retrieval.