This library provides a straightforward implementation of Minecraft's Rcon protocol in Python to provide a client for handling Remote Commands (RCON) to a Minecraft server.
The library is availble on PYPI and can be installed with pip:
pip install mcrcon
The recommend way to run this client is using the python 'with' statement. This ensures that the socket is correctly closed when you are done with it rather than being left open.
In : from mcrcon import MCRcon In : with MCRcon("10.1.1.1", "sekret") as mcr: ...: resp = mcr.command("/whitelist add bob") ...: print(resp)
While you can use it without the 'with' statement, you have to connect manually, and ideally disconnect:
In : mcr = MCRcon("10.1.1.1", "sekret") In : mcr.connect() In : resp = mcr.command("/whitelist add bob") In : print(resp) In : mcr.disconnect()