Search code examples
pythonuser-interfaceclient-server

How to equip python app with an arbitrary interface?


I am writing a small python app (a board game), currently I am writing the actual game with its logic.
Later on, I want to add a graphical Interface maybe with python, maybe in a different language, maybe as a web application, also a multiplayer option, maybe I'll host a server...

Is there a way to give my app an interface, so any of these possible extensions, are able to access the game, even if they are written in another language, run on another machine? I would like to add this interface once, so I don't have to change the entire base code for everything else I add.

So far I think I am looking for an API. However, every example I can find is about retriving and storing data from some database between a client and a remote server. Whereas, I will store all the data (for one session of the game) in the game's objects (its a boardgame, so it maybe 100 objects) and if I only add a GUI the communication I am looking for will happen between processes on the same machine.

Should I use something else (for example, I saw that I can define entry points when installing a python application via setuptools). Or, should I still use an API? If so, what protocol do you reccomend? Where should I start to learn?


Solution

  • For general communication (in future maybe over internet), you can use python socket.

    For the time being, you open a port on localhost and handle incoming commands accordingly.

    Here's a link to help you get started with sockets