core package

Module contents

Provides core functionality that doesn’t fit into any other package.

class core.AutoUnload[source]

Bases: object

Class used to auto unload specific instances.

Each inheriting class must implement an _unload_instance method.


alias of class

class core.GameConfigObj(infile, *args, **kwargs)[source]

Bases: configobj.ConfigObj

Class used to parse specific game data.

__init__(infile, *args, **kwargs)[source]

Helper class that merges the given file with engine/game files.

class core.WeakAutoUnload[source]

Bases: core.AutoUnload

Subclass of AutoUnload used to store weak references to instances.

class core.OutputReturn

Bases: Boost.Python.enum

BLOCK = _core.OutputReturn.BLOCK
CONTINUE = _core.OutputReturn.CONTINUE
names = {'BLOCK': _core.OutputReturn.BLOCK, 'CONTINUE': _core.OutputReturn.CONTINUE}
values = {0: _core.OutputReturn.BLOCK, 1: _core.OutputReturn.CONTINUE}

Return whether the output of sp info has been modified.

Parameters:output (str) – The output of sp info.
Raises:ValueError – Raised if the checksum was not found in the output.
Returns:True if the output has been modified.
Return type:bool
core.console_message((str)arg1) → None :

Output a message to the server console.

core.create_checksum(data, ignore_wchars=True)[source]

Create an MD5 checksum for the given string.

  • data (str) – The string for which a checksum should be created.
  • ignore_wchars (bool) – If True whitespace characters are ignored.
Return type:



Echo a message to the server’s console.


Unlike console_message, this function automatically adds a newline at the end of the message.

Parameters:text (str) – Message to print to the console.
core.get_core_modules() → list :

Return a list of all modules exposed by Source.Python’s core.

Return type:list
core.get_interface((str)arg1, (str)arg2) → object :

Retrieve an interface from a library.


Return the server’s public IPv4.

Return type:str


This functions makes a call to to retrieve the public IP.


Overwrite the strict codecs error handler temporarily.

This is useful e.g. if the engine truncates a string, which results in a string that contains a splitted multi-byte character at the end of the string.

Parameters:errors (str) – Error handler that will be looked up via codecs.lookup_error().
Raises:LookupError – Raised if the error handler was not found.


import memory

# Allocate four bytes to create an erroneous string
ptr = memory.alloc(4)

# Write data to the memory that will usually result in a
# UnicodeDecodeError
ptr.set_uchar(ord('a'), 0)
ptr.set_uchar(ord('b'), 1)
ptr.set_uchar(226, 2) # Add the invalid byte
ptr.set_uchar(0, 3) # Indicate the end of the string

with ignore_unicode_errors():
    # Read the data as a string. Now, it will only print 'ab', because
    # the invalid byte has been removed/ignored.

Gather all server output sent during the execution of the with-statement.

Parameters:action (OutputReturn) – Determines what happens with the output.
Return type:list
Returns:A list that will be filled with a tuple for every line that is being logged. The tuple contains the severity and the message.


from cvars import cvar
from core import server_output
from core import OutputReturn

status = cvar.find_command('status')

with server_output(OutputReturn.BLOCK) as output:

# Print everything that was logged by the 'status' command


[(_core.MessageSeverity.MESSAGE, 'hostname: Counter-Strike: Global Offensive\n'),
 (_core.MessageSeverity.MESSAGE, 'version : 513/6771 secure  [A:1:2435270659:8640] \n'),
 (_core.MessageSeverity.MESSAGE, 'udp/ip  :  (public ip:\n'),
 (_core.MessageSeverity.MESSAGE, 'os      :  Windows\n'),
 (_core.MessageSeverity.MESSAGE, 'type    :  community dedicated\n'),
 (_core.MessageSeverity.MESSAGE, 'players : 0 humans, 0 bots (20/0 max) (hibernating)\n\n'),
 (_core.MessageSeverity.MESSAGE, '# userid name uniqueid connected ping loss state rate'),
 (_core.MessageSeverity.MESSAGE, ' adr'),
 (_core.MessageSeverity.MESSAGE, '\n'),
 (_core.MessageSeverity.MESSAGE, '#end\n')]

The singleton object of the _CorePluginManager class.