This repository contains a collection of Python packages for OpenSIPS. These modules are designed to be as lightweight as possible and provide a simple interface for interacting with OpenSIPS.
Currently, the following packages are available:
mi
- can be used to execute OpenSIPS Management Interface (MI) commands.event
- allows you to use OpenSIPS Event Interface subscriptions.
-
Install the package from source code:
git clone cd python-opebsips pip install .
-
Import the package in your Python code:
from opensips.mi import OpenSIPSMI, OpenSIPSMIException from opensips.event import OpenSIPSEvent, OpenSIPSEventException
-
Use the methods provided by the modules:
mi = OpenSIPSMI('http', url='http://localhost:8888/mi') try: response = mi.execute('ps') # do something with the response except OpenSIPSMIException as e: # handle the exception
mi_connector = OpenSIPSMI('http', url='http://localhost:8888/mi') event = OpenSIPSEvent(mi_connector, 'datagram', ip='127.0.0.1', port=50012) def some_callback(message): # do something with the message pass try: event.subscribe('E_PIKE_BLOCKED', some_callback) except OpenSIPSEventException as e: # handle the exception try: event.unsubscribe('E_PIKE_BLOCKED') except OpenSIPSEventException as e: # handle the exception
- MI - contains information about supported MI communication types and required parameters for each type.
- Event Interface - lists the supported event transport protocols and provides information about the required parameters for each protocol.
After installing the package, you can use the provided opensips-mi script to run MI commands. This script takes the following arguments:
-t
or--type
- the type of the MI communication ()http
ordatagram
)-i
or--ip
- the IP address of the OpenSIPS server.-p
or--port
- the port of the OpenSIPS MI.
# general usage
opensips-mi -t datagram -p 8080 command_name [command_args ...]
# this will execute get_statistics command
opensips-mi -t datagram -p 8080 -s core: shmem:
# you can pass json string as argument with -j flag for commands that require arrays as arguments
opensips-mi -t datagram -p 8080 get_statistics -j "{'statistics': ['core:', 'shmem:']}"
The python-opensips
source code is licensed under the GNU General Public License v3.0
All documentation files (i.e. .md
extension) are licensed under the Creative Common License 4.0
© 2024 - OpenSIPS Solutions