Skip to main content

OpenSIPS Python Packages

Project description

OpenSIPS Python Packages

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. Alongside the source code, the repository also contains a Docker image that comes with the OpenSIPS Python packages pre-installed.

Features

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.

Usage

  1. Install the package from source code:

    git clone
    cd python-opensips
    pip install .
    

    or from PyPI:

    pip install opensips
    
  2. Import the package in your Python code:

    from opensips.mi import OpenSIPSMI, OpenSIPSMIException
    from opensips.event import OpenSIPSEvent, OpenSIPSEventException, OpenSIPSEventHandler
    
  3. 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')
    hdl = OpenSIPSEventHandler(mi_connector, 'datagram', ip='127.0.0.1', port=50012)
    
    def some_callback(message):
        # do something with the message (it is a JSON object)
        pass
    
    ev: OpenSIPSEvent = None
    try:
        event = hdl.subscribe('E_PIKE_BLOCKED', some_callback)
    except OpenSIPSEventException as e:
        # handle the exception
    
    try:
        ev.unsubscribe('E_PIKE_BLOCKED')
    except OpenSIPSEventException as e:
        # handle the exception
    

Documentation

  • 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.
  • Docker - provides information about the Docker image that contains the OpenSIPS Python packages.

Scripts

MI

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, datagram or fifo).
  • -i or --ip - the IP address of the OpenSIPS server.
  • -p or --port - the port of the OpenSIPS MI.
  • -f or --fifo-file - the path to the FIFO file.
  • -fb or --fifo-fallback - the path to the FIFO fallback file.
  • -fd or --fifo-reply-dir - the directory where the FIFO reply files are stored.
  • --env-file - the path to the environment file that contains the MI parameters (by default, the script will look for the .env file in the current directory); lower priority than the command line arguments.
  • -ds or --datagram-socket - Unix Datagram Socket.
  • -dt or --datagram-timeout - Datagram Socket timeout in seconds. Default is 0.1.
  • -db or --datagram-buffer-size - Datagram Socket buffer size in bytes. Default is 32768.

Usage

# 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:']}"

Event

You can use the provided opensips-event script to subscribe for OpenSIPS events. This script takes the following arguments:

  • all the above arguments for the MI communication
  • -T or --transport - the transport protocol to use (datagram, stream).
  • -li or --listen-ip - the IP address to listen on.
  • -lp or --listen-port - the port to listen on.
  • -e or --expire - the expiration time for the subscription.
  • the event name to subscribe for.
  • --env-file - the path to the environment file that contains the MI parameters (by default, the script will look for the .env file in the current directory); lower priority than the command line arguments.

Usage

opensips-event -t datagram -p 8080 -T datagram -lp 50012 -e 3600 E_PIKE_BLOCKED

License

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 Commons License 4.0

Creative Commons Logo

© 2024 - OpenSIPS Solutions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensips-0.1.9.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opensips-0.1.9-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file opensips-0.1.9.tar.gz.

File metadata

  • Download URL: opensips-0.1.9.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opensips-0.1.9.tar.gz
Algorithm Hash digest
SHA256 409a9078908c2321df0a727fdca700ac3300cae0e1d7ab01b0c92cc5314d213f
MD5 3bcad7642bfbf1475e75c5e404660455
BLAKE2b-256 ddca4eb6a144228e608380aa4261133551c32b604e1366b4861bf3f567d34f65

See more details on using hashes here.

Provenance

The following attestation bundles were made for opensips-0.1.9.tar.gz:

Publisher: pypi.yml on OpenSIPS/python-opensips

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opensips-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: opensips-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opensips-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 77d615827e6ce9926cd26be99b71b1fb49d633aa891678ba554aa0224b827128
MD5 b5ca18dbadf973b273dbe5f812411dec
BLAKE2b-256 a1f6b2658f94b96df5773856f05309d664d2817b7e50aa3343c570d9a6c97f0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for opensips-0.1.9-py3-none-any.whl:

Publisher: pypi.yml on OpenSIPS/python-opensips

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page