python_aternos package¶
Submodules¶
python_aternos.atclient module¶
- class python_aternos.atclient.Client(atconn: AternosConnect)¶
Bases:
object
Aternos API Client class whose object contains user’s auth data
- Parameters:
atconn (python_aternos.atconnect.AternosConnect) –
python_aternos.atconnect.AternosConnect
instance with initialized Aternos session
- change_email(value: str) None ¶
Changes an e-mail in your Aternos account
- Parameters:
value (str) – New e-mail
- Raises:
ValueError – If an invalid e-mail address is passed to the function
- change_password(old: str, new: str) None ¶
Changes a password in your Aternos account
- Parameters:
old (str) – Old password
new (str) – New password
- change_username(value: str) None ¶
Changes a username in your Aternos account
- Parameters:
value (str) – New username
- classmethod from_credentials(username: str, password: str)¶
Log in to Aternos with a username and a plain password
- Parameters:
username (str) – Your username
password (str) – Your password without any encryption
- Returns:
Client instance
- Return type:
- classmethod from_hashed(username: str, md5: str)¶
Log in to Aternos with a username and a hashed password
- Parameters:
username (str) – Your username
md5 (str) – Your password hashed with MD5
- Raises:
CredentialsError – If the API doesn’t return a valid session cookie
- Returns:
Client instance
- Return type:
- classmethod from_session(session: str)¶
Log in to Aternos using a session cookie value
- Parameters:
session (str) – Value of ATERNOS_SESSION cookie
- Returns:
Client instance
- Return type:
- get_server(servid: str) AternosServer ¶
Creates a server object from the server ID. Use this instead of list_servers if you know the ID to save some time.
- Returns:
- Return type:
- list_servers() List[AternosServer] ¶
Parses a list of your servers from Aternos website
- Returns:
List of
python_aternos.atserver.AternosServer
objects- Return type:
list
- static md5encode(passwd: str) str ¶
Encodes the given string with MD5
- Parameters:
passwd (str) – String to encode
- Returns:
Hexdigest hash of the string in lowercase
- Return type:
str
- classmethod restore_session(file: str = '~/.aternos')¶
Log in to Aternos using a saved ATERNOS_SESSION cookie
- Parameters:
file (str, optional) – File where a session cookie was saved, deafults to ~/.aternos
- Returns:
Client instance
- Return type:
- save_session(file: str = '~/.aternos') None ¶
Saves an ATERNOS_SESSION cookie to a file
- Parameters:
file (str, optional) – File where a session cookie must be saved, defaults to ~/.aternos
python_aternos.atconf module¶
- class python_aternos.atconf.AternosConfig(atserv: AternosServer)¶
Bases:
object
Class for editing server settings
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
object
- get_java() int ¶
Parses Java version from options page
- Returns:
Java image version
- Return type:
int
- get_server_props(proptyping: bool = True) Dict[str, Any] ¶
Parses all server.properties from options page
- Parameters:
proptyping – If the returned dict should contain value
that matches property type (e.g. max-players will be int) instead of string, defaults to True :type proptyping: bool, optional :return: Server.properties dict :rtype: Dict[str,Any]
- get_timezone() str ¶
Parses timezone from options page
- Returns:
Area/Location
- Return type:
str
- get_world_props(world: str = 'world', proptyping: bool = True) Dict[str, Any] ¶
Parses level.dat from specified world’s options page
- Parameters:
world (str, optional) – Name of the world, defaults to ‘world’
proptyping – If the returned dict should contain the value
that matches property type (e.g. randomTickSpeed will be bool) instead of string, defaults to True :type proptyping: bool, optional :return: Level.dat dict :rtype: Dict[str,Any]
- set_java(value: int) None ¶
Sets new Java version
- Parameters:
value (int) – New Java image version
- set_server_prop(option: str, value: Any) None ¶
Sets server.properties option
- Parameters:
option (str) – Option name
value (Any) – New value
- set_server_props(props: Dict[str, Any]) None ¶
Updates server.properties options with the given dict
- Parameters:
props (Dict[str,Any]) – Dict with properties {key:value}
- set_timezone(value: str) None ¶
Sets new timezone
- Parameters:
value (str) – New timezone
- Raises:
ValueError – If given string
doesn’t match Area/Location format
- set_world_prop(option: Union[WorldOpts, WorldRules], value: Any, gamerule: bool = False, world: str = 'world') None ¶
Sets level.dat option for specified world
- Parameters:
option (Union[WorldOpts,WorldRules]) – Option name
value (Any) – New value
gamerule – If the option
is a gamerule, defaults to False :type gamerule: bool, optional :param world: Name of the world which level.dat must be edited, defaults to ‘world’ :type world: str, optional
- set_world_props(props: Dict[str, Any]) None ¶
- class python_aternos.atconf.Difficulty(value)¶
Bases:
IntEnum
/difficulty numeric list
- easy = 1¶
- hard = 3¶
- normal = 2¶
- peaceful = 0¶
- class python_aternos.atconf.Gamemode(value)¶
Bases:
IntEnum
/gamemode numeric list
- adventure = 2¶
- creative = 1¶
- spectator = 3¶
- survival = 0¶
- class python_aternos.atconf.ServerOpts(value)¶
Bases:
Enum
server.options file
- animals = 'spawn-animals'¶
- cmdblock = 'enable-command-block'¶
- cmds = 'allow-cheats'¶
- difficulty = 'difficulty'¶
- flight = 'allow-flight'¶
- forcegm = 'force-gamemode'¶
- gm = 'gamemode'¶
- monsters = 'spawn-monsters'¶
- nether = 'allow-nether'¶
- online = 'online-mode'¶
- pack = 'resource-pack'¶
- packreq = 'require-resource-pack'¶
- players = 'max-players'¶
- pvp = 'pvp'¶
- spawnlock = 'spawn-protection'¶
- villagers = 'spawn-npcs'¶
- whl = 'white-list'¶
- class python_aternos.atconf.WorldOpts(value)¶
Bases:
Enum
level.dat file
- difficulty = 'Difficulty'¶
- hardcore = 'hardcore'¶
- seed = 'seed'¶
- seed12 = 'randomseed'¶
- class python_aternos.atconf.WorldRules(value)¶
Bases:
Enum
/gamerule list
- admincmdlog = 'logAdminCommands'¶
- advs = 'announceAdvancements'¶
- blockdrop = 'doTileDrops'¶
- cmdfb = 'sendCommandFeedback'¶
- cmdlen = 'maxCommandChainLength'¶
- cmdout = 'commandBlockOutput'¶
- daynight = 'doDaylightCycle'¶
- deathmsg = 'showDeathMessages'¶
- drowndmg = 'drowningDamage'¶
- elytra = 'disableElytraMovementCheck'¶
- entcram = 'maxEntityCramming'¶
- entdrop = 'doEntityDrops'¶
- falldmg = 'fallDamage'¶
- fire = 'doFireTick'¶
- firedmg = 'fireDamage'¶
- forgive = 'forgiveDeadPlayers'¶
- immrespawn = 'doImmediateRespawn'¶
- keepinv = 'keepInventory'¶
- limitcraft = 'doLimitedCrafting'¶
- mobgrief = 'mobGriefing'¶
- mobloot = 'doMobLoot'¶
- mobs = 'doMobSpawning'¶
- patrols = 'doPatrolSpawning'¶
- phantoms = 'doInsomnia'¶
- raids = 'disableRaids'¶
- reducedf3 = 'reducedDebugInfo'¶
- regen = 'naturalRegeneration'¶
- rndtick = 'randomTickSpeed'¶
- sleeppct = 'playersSleepingPercentage'¶
- snowdmg = 'freezeDamage'¶
- spawnradius = 'spawnRadius'¶
- spectchunkgen = 'spectatorsGenerateChunks'¶
- traders = 'doTraderSpawning'¶
- univanger = 'universalAnger'¶
- weather = 'doWeatherCycle'¶
python_aternos.atconnect module¶
- class python_aternos.atconnect.AternosConnect¶
Bases:
object
Class for sending API requests bypass Cloudflare and parsing responses
- convert_num(num: Union[int, float, str], base: int, frombase: int = 10) str ¶
Converts an integer to specified base
- Parameters:
num – Integer in any base to convert.
If it is a float started with 0,, zero and comma will be removed to get int :type num: Union[int,float,str] :param base: New base :type base: int :param frombase: Given number base, defaults to 10 :type frombase: int, optional :return: Number converted to a specified base :rtype: str
- generate_aternos_rand(randlen: int = 16) str ¶
Generates a random string using Aternos algorithm from main.js file
- Parameters:
randlen (int, optional) – Random string length, defaults to 16
- Returns:
Random string for SEC token
- Return type:
str
- generate_sec() str ¶
Generates Aternos SEC token which is also needed for most API requests
- Returns:
Random SEC key:value string
- Return type:
str
- parse_token() str ¶
Parses Aternos ajax token that is needed for most requests
- Raises:
RuntimeWarning – If the parser
can not find <head> tag in HTML response :raises CredentialsError: If the parser is unable to extract ajax token in HTML :return: Aternos ajax token :rtype: str
- request_cloudflare(url: str, method: str, params: Optional[dict] = None, data: Optional[dict] = None, headers: Optional[dict] = None, reqcookies: Optional[dict] = None, sendtoken: bool = False, redirect: bool = True, retry: int = 3) Response ¶
Sends a request to Aternos API bypass Cloudflare
- Parameters:
url (str) – Request URL
method (str) – Request method, must be GET or POST
params (Optional[dict], optional) – URL parameters, defaults to None
data – POST request data, if the method is GET,
this dict will be combined with params, defaults to None :type data: Optional[dict], optional :param headers: Custom headers, defaults to None :type headers: Optional[dict], optional :param reqcookies: Cookies only for this request, defaults to None :type reqcookies: Optional[dict], optional :param sendtoken: If the ajax and SEC token should be sent, defaults to False :type sendtoken: bool, optional :param redirect: If requests lib should follow Location header in 3xx responses, defaults to True :type redirect: bool, optional :param retry: How many times parser must retry connection to API bypass Cloudflare, defaults to 3 :type retry: int, optional :raises CloudflareError: When the parser has exceeded retries count :raises NotImplementedError: When the specified method is not GET or POST :return: API response :rtype: requests.Response
python_aternos.aterrors module¶
- exception python_aternos.aterrors.AternosError¶
Bases:
Exception
Common error class
- exception python_aternos.aterrors.CloudflareError¶
Bases:
AternosError
Raised when the parser is unable to bypass Cloudflare protection
- exception python_aternos.aterrors.CredentialsError¶
Bases:
AternosError
Raised when a session cookie is empty which means incorrect credentials
- exception python_aternos.aterrors.FileError¶
Bases:
AternosError
Raised when trying to execute a disallowed by Aternos file operation
- exception python_aternos.aterrors.ServerError¶
Bases:
AternosError
Common class for server errors
- exception python_aternos.aterrors.ServerEulaError¶
Bases:
ServerError
Raised when trying to start without confirming Mojang EULA
- exception python_aternos.aterrors.ServerRunningError¶
Bases:
ServerError
Raised when trying to start already running server
- exception python_aternos.aterrors.ServerSoftwareError¶
Bases:
ServerError
Raised when Aternos notifies about incorrect software version
- exception python_aternos.aterrors.ServerStorageError¶
Bases:
ServerError
Raised when Aternos notifies about violation of storage limits (4 GB for now)
- exception python_aternos.aterrors.TokenError¶
Bases:
AternosError
Raised when the parser is unable to extract Aternos ajax token
python_aternos.atfile module¶
- class python_aternos.atfile.AternosFile(atserv: AternosServer, path: str, name: str, ftype: FileType = FileType.file, size: Union[int, float] = 0)¶
Bases:
object
File class which contains info about its path, type and size
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
instancepath (str) – Path to the file
name (str) – Filename
ftype (python_aternos.atfile.FileType) – File or directory
size (Union[int,float], optional) – File size, defaults to 0
- delete() None ¶
Deletes the file
- property full: str¶
- get_content() bytes ¶
Requests file content in bytes (downloads it)
- Raises:
FileError – If downloading
the file is not allowed by Aternos :return: File content :rtype: bytes
- get_text() str ¶
Requests editing the file as a text (try it if downloading is disallowed)
- Returns:
File text content
- Return type:
str
- property is_dir: bool¶
- property is_file: bool¶
- property name: str¶
- property path¶
- set_content(value: bytes) None ¶
Modifies the file content
- Parameters:
value (bytes) – New content
- set_text(value: str) None ¶
Modifies the file content, but unlike set_content takes a string as a new value
- Parameters:
value (str) – New content
- property size: float¶
python_aternos.atfm module¶
- class python_aternos.atfm.FileManager(atserv: AternosServer)¶
Bases:
object
Aternos file manager class for viewing files structure
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
instance
- convert_size(num: Union[int, float], measure: str) float ¶
Converts “human” file size to size in bytes
- Parameters:
num (Union[int,float]) – Size
measure (str) – Units (B, kB, MB, GB)
- Returns:
Size in bytes
- Return type:
float
- dl_file(path: str) bytes ¶
Returns the file content in bytes (downloads it)
- Parameters:
path (str) – Path to file including its filename
- Returns:
File content
- Return type:
bytes
- dl_world(world: str = 'world') bytes ¶
Returns the world zip file content by its name (downloads it)
- Parameters:
world (str, optional) – Name of world, defaults to ‘world’
- Returns:
Zip file content
- Return type:
bytes
- get_file(path: str) Optional[AternosFile] ¶
Returns
python_aternos.atfile.AternosFile
instance by its path- Parameters:
path (str) – Path to file including its filename
- Returns:
_description_
- Return type:
Optional[AternosFile]
- listdir(path: str = '') List[AternosFile] ¶
Requests a list of files in the specified directory
- Parameters:
path – Directory
(an empty string means root), defaults to ‘’ :type path: str, optional :return: List of
python_aternos.atfile.AternosFile
:rtype: List[AternosFile]
python_aternos.atjsparse module¶
- python_aternos.atjsparse.atob(s: str) str ¶
- python_aternos.atjsparse.exec(f: str) Any ¶
Executes a JavaScript function
- Parameters:
f (str) – ECMA6 function
- Returns:
JavaScript interpreter context
- Return type:
Any
- python_aternos.atjsparse.to_ecma5_function(f: str) str ¶
Converts a ECMA6 function to ECMA5 format (without arrow expressions)
- Parameters:
f (str) – ECMA6 function
- Returns:
ECMA5 function
- Return type:
str
python_aternos.atplayers module¶
- class python_aternos.atplayers.Lists(value)¶
Bases:
Enum
An enumeration.
- ban = 'banned-players'¶
- ips = 'banned-ips'¶
- ops = 'ops'¶
- whl = 'whitelist'¶
- class python_aternos.atplayers.PlayersList(lst: Union[str, Lists], atserv: AternosServer)¶
Bases:
object
Class for managing operators, whitelist and banned players lists
- Parameters:
lst – Players list type, must be
python_aternos.atplayers.Lists
enum value :type lst: Union[str,Lists] :param atserv:python_aternos.atserver.AternosServer
instance :type atserv: python_aternos.atserver.AternosServer- add(name: str) None ¶
Appends a player to the list by the nickname
- Parameters:
name (str) – Player’s nickname
- list_players(cache: bool = True) List[str] ¶
Parse a players list
- Parameters:
cache (bool, optional) – If the function can return cached list (highly recommended), defaults to True
- Returns:
List of players nicknames
- Return type:
List[str]
- remove(name: str) None ¶
Removes a player from the list by the nickname
- Parameters:
name (str) – Player’s nickname
python_aternos.atserver module¶
- class python_aternos.atserver.AternosServer(servid: str, atconn: AternosConnect, reqinfo: bool = True)¶
Bases:
object
Class for controlling your Aternos Minecraft server
- Parameters:
servid (str) – Unique server IDentifier
instance with initialized Aternos session :type atconn: python_aternos.atconnect.AternosConnect :param reqinfo: Automatically call AternosServer.fetch() to get all info, defaults to True :type reqinfo: bool, optional
- property address: str¶
- atserver_request(url: str, method: str, params: Optional[dict] = None, data: Optional[dict] = None, headers: Optional[dict] = None, sendtoken: bool = False) Response ¶
Sends a request to Aternos API with server IDenitfier parameter
- Parameters:
url (str) – Request URL
method (str) – Request method, must be GET or POST
params (Optional[dict], optional) – URL parameters, defaults to None
data – POST request data, if the method is GET,
this dict will be combined with params, defaults to None :type data: Optional[dict], optional :param headers: Custom headers, defaults to None :type headers: Optional[dict], optional :param sendtoken: If the ajax and SEC token should be sent, defaults to False :type sendtoken: bool, optional :return: API response :rtype: requests.Response
- cancel() None ¶
Cancels server launching
- config() AternosConfig ¶
Returns
python_aternos.atconf.AternosConfig
instance for editing server settings- Returns:
- Return type:
- confirm() None ¶
Confirms server launching
- property domain: str¶
- property edition: int¶
- eula() None ¶
Accepts the Mojang EULA
- fetch() None ¶
Send a request to Aternos API to get all server info
- files() FileManager ¶
Returns
python_aternos.atfm.FileManager
instance for file operations- Returns:
- Return type:
- property motd: str¶
- players(lst: Lists) PlayersList ¶
Returns
python_aternos.atplayers.PlayersList
instance for managing operators, whitelist and banned players lists- Parameters:
lst – Players list type, must be
the
python_aternos.atplayers.Lists
enum value :type lst: python_aternos.atplayers.Lists :return:python_aternos.atplayers.PlayersList
:rtype: python_aternos.atplayers.PlayersList
- property players_count: int¶
- property players_list: List[str]¶
- property port: int¶
- property ram: int¶
- restart() None ¶
Restarts the server
- property slots: int¶
- property software: str¶
- start(headstart: bool = False, accepteula: bool = True) None ¶
Starts a server
- Parameters:
headstart (bool, optional) – Start a server in the headstart mode which allows you to skip all queue, defaults to False
accepteula (bool, optional) – Automatically accept the Mojang EULA, defaults to True
- Raises:
ServerEulaError – When trying to start a server
without accepting the Mojang EULA :raises ServerRunningError: When trying to start a server which is alreday running :raises ServerSoftwareError: When Aternos notifies about incorrect software version :raises ServerStorageError: When Aternos notifies about voilation of storage limits (4 GB for now) :raises ServerError: When API is unable to start a Minecraft server due to unavailability of Aternos’ file servers or other problems
- property status: str¶
- property status_num: int¶
- stop() None ¶
Stops the server
- property subdomain: str¶
- property version: str¶
- wss(autoconfirm: bool = False) AternosWss ¶
Returns
python_aternos.atwss.AternosWss
instance for listening server streams in real-time- Parameters:
autoconfirm – Automatically start server status listener
when AternosWss connects to API to confirm server launching, defaults to False :type autoconfirm: bool, optional :return:
python_aternos.atwss.AternosWss
object :rtype: python_aternos.atwss.AternosWss
python_aternos.atwss module¶
- class python_aternos.atwss.AternosWss(atserv: AternosServer, autoconfirm: bool = False)¶
Bases:
object
Class for managing websocket connection
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
instanceautoconfirm – Automatically start server status listener
when AternosWss connects to API to confirm server launching, defaults to False :type autoconfirm: bool, optional
- async close() None ¶
Closes websocket connection and stops all listeners
- async confirm() None ¶
Simple way to call AternosServer.confirm from this class
- async connect() None ¶
Connect to the websocket server and start all stream listeners
- async keepalive() None ¶
Each 49 seconds sends keepalive ping to websocket server
- async receiver() None ¶
Receives messages from websocket servers and calls user’s streams listeners
- async send(obj: Union[Dict[str, Any], str]) None ¶
Sends a message to websocket server
- Parameters:
obj (Union[Dict[str, Any],str]) – Message, may be a string or a dict
- wssreceiver(stream: Streams, *args: Any) Callable[[Callable[[Any], Coroutine[Any, Any, None]]], Any] ¶
Decorator that marks your function as a stream receiver. When websocket receives message from the specified stream, it calls all listeners created with this decorator.
- Parameters:
stream (python_aternos.atwss.Streams) – Stream that your function should listen
args (tuple, optional) – Arguments which will be passed to your function
- Returns:
…
- Return type:
Callable[[Callable[[Any],Coroutine[Any,Any,None]]],Any]
- async wssworker() None ¶
Starts async tasks in background for receiving websocket messages and sending keepalive ping
Module contents¶
- class python_aternos.AternosConfig(atserv: AternosServer)¶
Bases:
object
Class for editing server settings
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
object
- get_java() int ¶
Parses Java version from options page
- Returns:
Java image version
- Return type:
int
- get_server_props(proptyping: bool = True) Dict[str, Any] ¶
Parses all server.properties from options page
- Parameters:
proptyping – If the returned dict should contain value
that matches property type (e.g. max-players will be int) instead of string, defaults to True :type proptyping: bool, optional :return: Server.properties dict :rtype: Dict[str,Any]
- get_timezone() str ¶
Parses timezone from options page
- Returns:
Area/Location
- Return type:
str
- get_world_props(world: str = 'world', proptyping: bool = True) Dict[str, Any] ¶
Parses level.dat from specified world’s options page
- Parameters:
world (str, optional) – Name of the world, defaults to ‘world’
proptyping – If the returned dict should contain the value
that matches property type (e.g. randomTickSpeed will be bool) instead of string, defaults to True :type proptyping: bool, optional :return: Level.dat dict :rtype: Dict[str,Any]
- set_java(value: int) None ¶
Sets new Java version
- Parameters:
value (int) – New Java image version
- set_server_prop(option: str, value: Any) None ¶
Sets server.properties option
- Parameters:
option (str) – Option name
value (Any) – New value
- set_server_props(props: Dict[str, Any]) None ¶
Updates server.properties options with the given dict
- Parameters:
props (Dict[str,Any]) – Dict with properties {key:value}
- set_timezone(value: str) None ¶
Sets new timezone
- Parameters:
value (str) – New timezone
- Raises:
ValueError – If given string
doesn’t match Area/Location format
- set_world_prop(option: Union[WorldOpts, WorldRules], value: Any, gamerule: bool = False, world: str = 'world') None ¶
Sets level.dat option for specified world
- Parameters:
option (Union[WorldOpts,WorldRules]) – Option name
value (Any) – New value
gamerule – If the option
is a gamerule, defaults to False :type gamerule: bool, optional :param world: Name of the world which level.dat must be edited, defaults to ‘world’ :type world: str, optional
- set_world_props(props: Dict[str, Any]) None ¶
- class python_aternos.AternosConnect¶
Bases:
object
Class for sending API requests bypass Cloudflare and parsing responses
- convert_num(num: Union[int, float, str], base: int, frombase: int = 10) str ¶
Converts an integer to specified base
- Parameters:
num – Integer in any base to convert.
If it is a float started with 0,, zero and comma will be removed to get int :type num: Union[int,float,str] :param base: New base :type base: int :param frombase: Given number base, defaults to 10 :type frombase: int, optional :return: Number converted to a specified base :rtype: str
- generate_aternos_rand(randlen: int = 16) str ¶
Generates a random string using Aternos algorithm from main.js file
- Parameters:
randlen (int, optional) – Random string length, defaults to 16
- Returns:
Random string for SEC token
- Return type:
str
- generate_sec() str ¶
Generates Aternos SEC token which is also needed for most API requests
- Returns:
Random SEC key:value string
- Return type:
str
- parse_token() str ¶
Parses Aternos ajax token that is needed for most requests
- Raises:
RuntimeWarning – If the parser
can not find <head> tag in HTML response :raises CredentialsError: If the parser is unable to extract ajax token in HTML :return: Aternos ajax token :rtype: str
- request_cloudflare(url: str, method: str, params: Optional[dict] = None, data: Optional[dict] = None, headers: Optional[dict] = None, reqcookies: Optional[dict] = None, sendtoken: bool = False, redirect: bool = True, retry: int = 3) Response ¶
Sends a request to Aternos API bypass Cloudflare
- Parameters:
url (str) – Request URL
method (str) – Request method, must be GET or POST
params (Optional[dict], optional) – URL parameters, defaults to None
data – POST request data, if the method is GET,
this dict will be combined with params, defaults to None :type data: Optional[dict], optional :param headers: Custom headers, defaults to None :type headers: Optional[dict], optional :param reqcookies: Cookies only for this request, defaults to None :type reqcookies: Optional[dict], optional :param sendtoken: If the ajax and SEC token should be sent, defaults to False :type sendtoken: bool, optional :param redirect: If requests lib should follow Location header in 3xx responses, defaults to True :type redirect: bool, optional :param retry: How many times parser must retry connection to API bypass Cloudflare, defaults to 3 :type retry: int, optional :raises CloudflareError: When the parser has exceeded retries count :raises NotImplementedError: When the specified method is not GET or POST :return: API response :rtype: requests.Response
- exception python_aternos.AternosError¶
Bases:
Exception
Common error class
- class python_aternos.AternosFile(atserv: AternosServer, path: str, name: str, ftype: FileType = FileType.file, size: Union[int, float] = 0)¶
Bases:
object
File class which contains info about its path, type and size
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
instancepath (str) – Path to the file
name (str) – Filename
ftype (python_aternos.atfile.FileType) – File or directory
size (Union[int,float], optional) – File size, defaults to 0
- delete() None ¶
Deletes the file
- property full: str¶
- get_content() bytes ¶
Requests file content in bytes (downloads it)
- Raises:
FileError – If downloading
the file is not allowed by Aternos :return: File content :rtype: bytes
- get_text() str ¶
Requests editing the file as a text (try it if downloading is disallowed)
- Returns:
File text content
- Return type:
str
- property is_dir: bool¶
- property is_file: bool¶
- property name: str¶
- property path¶
- set_content(value: bytes) None ¶
Modifies the file content
- Parameters:
value (bytes) – New content
- set_text(value: str) None ¶
Modifies the file content, but unlike set_content takes a string as a new value
- Parameters:
value (str) – New content
- property size: float¶
- class python_aternos.AternosServer(servid: str, atconn: AternosConnect, reqinfo: bool = True)¶
Bases:
object
Class for controlling your Aternos Minecraft server
- Parameters:
servid (str) – Unique server IDentifier
instance with initialized Aternos session :type atconn: python_aternos.atconnect.AternosConnect :param reqinfo: Automatically call AternosServer.fetch() to get all info, defaults to True :type reqinfo: bool, optional
- property address: str¶
- atserver_request(url: str, method: str, params: Optional[dict] = None, data: Optional[dict] = None, headers: Optional[dict] = None, sendtoken: bool = False) Response ¶
Sends a request to Aternos API with server IDenitfier parameter
- Parameters:
url (str) – Request URL
method (str) – Request method, must be GET or POST
params (Optional[dict], optional) – URL parameters, defaults to None
data – POST request data, if the method is GET,
this dict will be combined with params, defaults to None :type data: Optional[dict], optional :param headers: Custom headers, defaults to None :type headers: Optional[dict], optional :param sendtoken: If the ajax and SEC token should be sent, defaults to False :type sendtoken: bool, optional :return: API response :rtype: requests.Response
- cancel() None ¶
Cancels server launching
- config() AternosConfig ¶
Returns
python_aternos.atconf.AternosConfig
instance for editing server settings- Returns:
- Return type:
- confirm() None ¶
Confirms server launching
- property domain: str¶
- property edition: int¶
- eula() None ¶
Accepts the Mojang EULA
- fetch() None ¶
Send a request to Aternos API to get all server info
- files() FileManager ¶
Returns
python_aternos.atfm.FileManager
instance for file operations- Returns:
- Return type:
- property motd: str¶
- players(lst: Lists) PlayersList ¶
Returns
python_aternos.atplayers.PlayersList
instance for managing operators, whitelist and banned players lists- Parameters:
lst – Players list type, must be
the
python_aternos.atplayers.Lists
enum value :type lst: python_aternos.atplayers.Lists :return:python_aternos.atplayers.PlayersList
:rtype: python_aternos.atplayers.PlayersList
- property players_count: int¶
- property players_list: List[str]¶
- property port: int¶
- property ram: int¶
- restart() None ¶
Restarts the server
- property slots: int¶
- property software: str¶
- start(headstart: bool = False, accepteula: bool = True) None ¶
Starts a server
- Parameters:
headstart (bool, optional) – Start a server in the headstart mode which allows you to skip all queue, defaults to False
accepteula (bool, optional) – Automatically accept the Mojang EULA, defaults to True
- Raises:
ServerEulaError – When trying to start a server
without accepting the Mojang EULA :raises ServerRunningError: When trying to start a server which is alreday running :raises ServerSoftwareError: When Aternos notifies about incorrect software version :raises ServerStorageError: When Aternos notifies about voilation of storage limits (4 GB for now) :raises ServerError: When API is unable to start a Minecraft server due to unavailability of Aternos’ file servers or other problems
- property status: str¶
- property status_num: int¶
- stop() None ¶
Stops the server
- property subdomain: str¶
- property version: str¶
- wss(autoconfirm: bool = False) AternosWss ¶
Returns
python_aternos.atwss.AternosWss
instance for listening server streams in real-time- Parameters:
autoconfirm – Automatically start server status listener
when AternosWss connects to API to confirm server launching, defaults to False :type autoconfirm: bool, optional :return:
python_aternos.atwss.AternosWss
object :rtype: python_aternos.atwss.AternosWss
- class python_aternos.AternosWss(atserv: AternosServer, autoconfirm: bool = False)¶
Bases:
object
Class for managing websocket connection
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
instanceautoconfirm – Automatically start server status listener
when AternosWss connects to API to confirm server launching, defaults to False :type autoconfirm: bool, optional
- async close() None ¶
Closes websocket connection and stops all listeners
- async confirm() None ¶
Simple way to call AternosServer.confirm from this class
- async connect() None ¶
Connect to the websocket server and start all stream listeners
- async keepalive() None ¶
Each 49 seconds sends keepalive ping to websocket server
- async receiver() None ¶
Receives messages from websocket servers and calls user’s streams listeners
- async send(obj: Union[Dict[str, Any], str]) None ¶
Sends a message to websocket server
- Parameters:
obj (Union[Dict[str, Any],str]) – Message, may be a string or a dict
- wssreceiver(stream: Streams, *args: Any) Callable[[Callable[[Any], Coroutine[Any, Any, None]]], Any] ¶
Decorator that marks your function as a stream receiver. When websocket receives message from the specified stream, it calls all listeners created with this decorator.
- Parameters:
stream (python_aternos.atwss.Streams) – Stream that your function should listen
args (tuple, optional) – Arguments which will be passed to your function
- Returns:
…
- Return type:
Callable[[Callable[[Any],Coroutine[Any,Any,None]]],Any]
- async wssworker() None ¶
Starts async tasks in background for receiving websocket messages and sending keepalive ping
- class python_aternos.Client(atconn: AternosConnect)¶
Bases:
object
Aternos API Client class whose object contains user’s auth data
- Parameters:
atconn (python_aternos.atconnect.AternosConnect) –
python_aternos.atconnect.AternosConnect
instance with initialized Aternos session
- change_email(value: str) None ¶
Changes an e-mail in your Aternos account
- Parameters:
value (str) – New e-mail
- Raises:
ValueError – If an invalid e-mail address is passed to the function
- change_password(old: str, new: str) None ¶
Changes a password in your Aternos account
- Parameters:
old (str) – Old password
new (str) – New password
- change_username(value: str) None ¶
Changes a username in your Aternos account
- Parameters:
value (str) – New username
- classmethod from_credentials(username: str, password: str)¶
Log in to Aternos with a username and a plain password
- Parameters:
username (str) – Your username
password (str) – Your password without any encryption
- Returns:
Client instance
- Return type:
- classmethod from_hashed(username: str, md5: str)¶
Log in to Aternos with a username and a hashed password
- Parameters:
username (str) – Your username
md5 (str) – Your password hashed with MD5
- Raises:
CredentialsError – If the API doesn’t return a valid session cookie
- Returns:
Client instance
- Return type:
- classmethod from_session(session: str)¶
Log in to Aternos using a session cookie value
- Parameters:
session (str) – Value of ATERNOS_SESSION cookie
- Returns:
Client instance
- Return type:
- get_server(servid: str) AternosServer ¶
Creates a server object from the server ID. Use this instead of list_servers if you know the ID to save some time.
- Returns:
- Return type:
- list_servers() List[AternosServer] ¶
Parses a list of your servers from Aternos website
- Returns:
List of
python_aternos.atserver.AternosServer
objects- Return type:
list
- static md5encode(passwd: str) str ¶
Encodes the given string with MD5
- Parameters:
passwd (str) – String to encode
- Returns:
Hexdigest hash of the string in lowercase
- Return type:
str
- classmethod restore_session(file: str = '~/.aternos')¶
Log in to Aternos using a saved ATERNOS_SESSION cookie
- Parameters:
file (str, optional) – File where a session cookie was saved, deafults to ~/.aternos
- Returns:
Client instance
- Return type:
- save_session(file: str = '~/.aternos') None ¶
Saves an ATERNOS_SESSION cookie to a file
- Parameters:
file (str, optional) – File where a session cookie must be saved, defaults to ~/.aternos
- exception python_aternos.CloudflareError¶
Bases:
AternosError
Raised when the parser is unable to bypass Cloudflare protection
- exception python_aternos.CredentialsError¶
Bases:
AternosError
Raised when a session cookie is empty which means incorrect credentials
- class python_aternos.Difficulty(value)¶
Bases:
IntEnum
/difficulty numeric list
- easy = 1¶
- hard = 3¶
- normal = 2¶
- peaceful = 0¶
- exception python_aternos.FileError¶
Bases:
AternosError
Raised when trying to execute a disallowed by Aternos file operation
- class python_aternos.FileManager(atserv: AternosServer)¶
Bases:
object
Aternos file manager class for viewing files structure
- Parameters:
atserv (python_aternos.atserver.AternosServer) –
python_aternos.atserver.AternosServer
instance
- convert_size(num: Union[int, float], measure: str) float ¶
Converts “human” file size to size in bytes
- Parameters:
num (Union[int,float]) – Size
measure (str) – Units (B, kB, MB, GB)
- Returns:
Size in bytes
- Return type:
float
- dl_file(path: str) bytes ¶
Returns the file content in bytes (downloads it)
- Parameters:
path (str) – Path to file including its filename
- Returns:
File content
- Return type:
bytes
- dl_world(world: str = 'world') bytes ¶
Returns the world zip file content by its name (downloads it)
- Parameters:
world (str, optional) – Name of world, defaults to ‘world’
- Returns:
Zip file content
- Return type:
bytes
- get_file(path: str) Optional[AternosFile] ¶
Returns
python_aternos.atfile.AternosFile
instance by its path- Parameters:
path (str) – Path to file including its filename
- Returns:
_description_
- Return type:
Optional[AternosFile]
- listdir(path: str = '') List[AternosFile] ¶
Requests a list of files in the specified directory
- Parameters:
path – Directory
(an empty string means root), defaults to ‘’ :type path: str, optional :return: List of
python_aternos.atfile.AternosFile
:rtype: List[AternosFile]
- class python_aternos.Gamemode(value)¶
Bases:
IntEnum
/gamemode numeric list
- adventure = 2¶
- creative = 1¶
- spectator = 3¶
- survival = 0¶
- class python_aternos.Lists(value)¶
Bases:
Enum
An enumeration.
- ban = 'banned-players'¶
- ips = 'banned-ips'¶
- ops = 'ops'¶
- whl = 'whitelist'¶
- class python_aternos.PlayersList(lst: Union[str, Lists], atserv: AternosServer)¶
Bases:
object
Class for managing operators, whitelist and banned players lists
- Parameters:
lst – Players list type, must be
python_aternos.atplayers.Lists
enum value :type lst: Union[str,Lists] :param atserv:python_aternos.atserver.AternosServer
instance :type atserv: python_aternos.atserver.AternosServer- add(name: str) None ¶
Appends a player to the list by the nickname
- Parameters:
name (str) – Player’s nickname
- list_players(cache: bool = True) List[str] ¶
Parse a players list
- Parameters:
cache (bool, optional) – If the function can return cached list (highly recommended), defaults to True
- Returns:
List of players nicknames
- Return type:
List[str]
- remove(name: str) None ¶
Removes a player from the list by the nickname
- Parameters:
name (str) – Player’s nickname
- exception python_aternos.ServerError¶
Bases:
AternosError
Common class for server errors
- exception python_aternos.ServerEulaError¶
Bases:
ServerError
Raised when trying to start without confirming Mojang EULA
- class python_aternos.ServerOpts(value)¶
Bases:
Enum
server.options file
- animals = 'spawn-animals'¶
- cmdblock = 'enable-command-block'¶
- cmds = 'allow-cheats'¶
- difficulty = 'difficulty'¶
- flight = 'allow-flight'¶
- forcegm = 'force-gamemode'¶
- gm = 'gamemode'¶
- monsters = 'spawn-monsters'¶
- nether = 'allow-nether'¶
- online = 'online-mode'¶
- pack = 'resource-pack'¶
- packreq = 'require-resource-pack'¶
- players = 'max-players'¶
- pvp = 'pvp'¶
- spawnlock = 'spawn-protection'¶
- villagers = 'spawn-npcs'¶
- whl = 'white-list'¶
- exception python_aternos.ServerRunningError¶
Bases:
ServerError
Raised when trying to start already running server
- exception python_aternos.ServerSoftwareError¶
Bases:
ServerError
Raised when Aternos notifies about incorrect software version
- exception python_aternos.ServerStorageError¶
Bases:
ServerError
Raised when Aternos notifies about violation of storage limits (4 GB for now)
- class python_aternos.Status(value)¶
Bases:
IntEnum
Server numeric status enum. It is highly recommended to use AternosServer.status instead of AternosServer.status_num
- confirm = 10¶
- error = 7¶
- off = 0¶
- on = 1¶
- shutdown = 3¶
- starting = 2¶
- unknown = 6¶
- class python_aternos.Streams(value)¶
Bases:
Enum
WebSocket streams types
- console = (2, 'console')¶
- queue = (1, None)¶
- ram = (3, 'heap')¶
- status = (0, None)¶
- tps = (4, 'tick')¶
- exception python_aternos.TokenError¶
Bases:
AternosError
Raised when the parser is unable to extract Aternos ajax token
- class python_aternos.WorldOpts(value)¶
Bases:
Enum
level.dat file
- difficulty = 'Difficulty'¶
- hardcore = 'hardcore'¶
- seed = 'seed'¶
- seed12 = 'randomseed'¶
- class python_aternos.WorldRules(value)¶
Bases:
Enum
/gamerule list
- admincmdlog = 'logAdminCommands'¶
- advs = 'announceAdvancements'¶
- blockdrop = 'doTileDrops'¶
- cmdfb = 'sendCommandFeedback'¶
- cmdlen = 'maxCommandChainLength'¶
- cmdout = 'commandBlockOutput'¶
- daynight = 'doDaylightCycle'¶
- deathmsg = 'showDeathMessages'¶
- drowndmg = 'drowningDamage'¶
- elytra = 'disableElytraMovementCheck'¶
- entcram = 'maxEntityCramming'¶
- entdrop = 'doEntityDrops'¶
- falldmg = 'fallDamage'¶
- fire = 'doFireTick'¶
- firedmg = 'fireDamage'¶
- forgive = 'forgiveDeadPlayers'¶
- immrespawn = 'doImmediateRespawn'¶
- keepinv = 'keepInventory'¶
- limitcraft = 'doLimitedCrafting'¶
- mobgrief = 'mobGriefing'¶
- mobloot = 'doMobLoot'¶
- mobs = 'doMobSpawning'¶
- patrols = 'doPatrolSpawning'¶
- phantoms = 'doInsomnia'¶
- raids = 'disableRaids'¶
- reducedf3 = 'reducedDebugInfo'¶
- regen = 'naturalRegeneration'¶
- rndtick = 'randomTickSpeed'¶
- sleeppct = 'playersSleepingPercentage'¶
- snowdmg = 'freezeDamage'¶
- spawnradius = 'spawnRadius'¶
- spectchunkgen = 'spectatorsGenerateChunks'¶
- traders = 'doTraderSpawning'¶
- univanger = 'universalAnger'¶
- weather = 'doWeatherCycle'¶
- python_aternos.atob(s: str) str ¶
- python_aternos.exec(f: str) Any ¶
Executes a JavaScript function
- Parameters:
f (str) – ECMA6 function
- Returns:
JavaScript interpreter context
- Return type:
Any
- python_aternos.to_ecma5_function(f: str) str ¶
Converts a ECMA6 function to ECMA5 format (without arrow expressions)
- Parameters:
f (str) – ECMA6 function
- Returns:
ECMA5 function
- Return type:
str