|
| 1 | +# OpenSIPS Python Packages |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +Currently, the following packages are available: |
| 8 | +- `mi` - can be used to execute OpenSIPS Management Interface (MI) commands. |
| 9 | +- `event` - allows you to use OpenSIPS Event Interface subscriptions. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +1. Install the package from source code: |
| 14 | + |
| 15 | + ```bash |
| 16 | + git clone |
| 17 | + cd python-opebsips |
| 18 | + pip install . |
| 19 | + ``` |
| 20 | + |
| 21 | +2. Import the package in your Python code: |
| 22 | + |
| 23 | + ```python |
| 24 | + from opensips.mi import OpenSIPSMI, OpenSIPSMIException |
| 25 | + from opensips.event import OpenSIPSEvent, OpenSIPSEventException |
| 26 | + ``` |
| 27 | + |
| 28 | +3. Use the methods provided by the modules: |
| 29 | + |
| 30 | + ```python |
| 31 | + mi = OpenSIPSMI('http', url='http://localhost:8888/mi') |
| 32 | + try: |
| 33 | + response = mi.execute('ps') |
| 34 | + # do something with the response |
| 35 | + except OpenSIPSMIException as e: |
| 36 | + # handle the exception |
| 37 | + ``` |
| 38 | + |
| 39 | + ```python |
| 40 | + mi_connector = OpenSIPSMI('http', url='http://localhost:8888/mi') |
| 41 | + event = OpenSIPSEvent(mi_connector, 'datagram', ip='127.0.0.1', port=50012) |
| 42 | +
|
| 43 | + def some_callback(message): |
| 44 | + # do something with the message |
| 45 | + pass |
| 46 | +
|
| 47 | + try: |
| 48 | + event.subscribe('E_PIKE_BLOCKED', some_callback) |
| 49 | + except OpenSIPSEventException as e: |
| 50 | + # handle the exception |
| 51 | +
|
| 52 | + try: |
| 53 | + event.unsubscribe('E_PIKE_BLOCKED') |
| 54 | + except OpenSIPSEventException as e: |
| 55 | + # handle the exception |
| 56 | + ``` |
| 57 | + |
| 58 | +## Documentation |
| 59 | + |
| 60 | +* [MI](docs/mi.md) - contains information about supported MI communication types and required parameters for each type. |
| 61 | +* [Event Interface](docs/event.md) - lists the supported event transport protocols and provides information about the required parameters for each protocol. |
| 62 | + |
| 63 | +## License |
| 64 | + |
| 65 | +<!-- License source --> |
| 66 | +[License-GPLv3]: https://www.gnu.org/licenses/gpl-3.0.en.html "GNU GPLv3" |
| 67 | +[Logo-CC_BY]: https://i.creativecommons.org/l/by/4.0/88x31.png "Creative Common Logo" |
| 68 | +[License-CC_BY]: https://creativecommons.org/licenses/by/4.0/legalcode "Creative Common License" |
| 69 | + |
| 70 | +The `python-opensips` source code is licensed under the [GNU General Public License v3.0][License-GPLv3] |
| 71 | + |
| 72 | +All documentation files (i.e. `.md` extension) are licensed under the [Creative Common License 4.0][License-CC_BY] |
| 73 | + |
| 74 | +![Creative Common Logo][Logo-CC_BY] |
| 75 | + |
| 76 | +© 2024 - OpenSIPS Solutions |
0 commit comments