Send messages and files to Cisco Webex.
Project description
notify-to-cisco-webex/README.md#L1-200
notify-to-cisco-webex
Overview
A small Python module and CLI for sending messages (and file attachments) to Cisco Webex. It can be used both as a Python library (programmatic API) and as a command-line tool.
Key features
- Send text or markdown messages.
- Attach files (one file per Webex message; when multiple files are supplied the tool sends one message per file and includes the message body only on the first send).
- Configuration via constructor arguments, OS environment variables, or a
.envfile (priority: constructor args > environment > .env). - TLS verification toggle, proxy support, and request timeout.
- Returns API responses as parsed JSON when operations succeed.
- Minimal external dependencies:
dotenvandhttpx.
Requirements
- Python 3.14+ (project metadata)
- External packages:
dotenv(for loading .env)httpx(for HTTP)
- (Dev)
pytestfor running tests
Installation
Install the package and its dependencies. Examples:
- Editable install for development:
python -m pip install -e .
- Install production deps (after building or from PyPI if published):
python -m pip install .
Configuration / Environment variables
The following environment variables (or entries in a .env file) are supported:
WEBEX_ACCESS_TOKEN— Webex access token (required unless supplied to constructor/CLI).WEBEX_ROOM_ID— Room ID to post messages to (optional ifWEBEX_TO_EMAILis used).WEBEX_TO_EMAIL— Recipient email address (optional ifWEBEX_ROOM_IDis used).WEBEX_PROXY— Optional HTTP proxy URL (passed to httpx).
Priority for configuration when creating a Webex object:
- Constructor arguments
- OS environment variables
.envfile
Note: If both room_id and to_email are provided, room_id takes precedence.
Using the Python module
Import and use the Webex class to send messages programmatically.
Example:
from notify_to_cisco_webex.notify_to_cisco_webex import Webex
# Create a client (constructor args override environment)
client = Webex(access_token="MY_TOKEN", room_id="ROOM_ID")
# Send a message (no attachments)
response = client.send_message(message="Hello from Python!", format="markdown")
print(response)
# Send message with multiple attachments (will POST one message per file;
# the message body is included only for the first file)
files = ["./image1.png", "./doc.pdf"]
responses = client.send_message(message="Files attached", format="markdown", files=files)
print(responses)
API notes:
formataccepts"markdown"or"text".- When multiple files are passed, the return value is a list of response JSON objects (one per sent message). When a single file or no files is used, a single dict is returned for convenience.
- Errors raise
WebexErrorwith a descriptive message.
Using the CLI
A CLI entrypoint is provided. There are multiple ways to run the CLI depending on how you have installed or are running the package. All of the following are supported after installation:
- Module invocation (short module):
python -m notify_to_cisco_webex - Module invocation (explicit module file):
python -m notify_to_cisco_webex.notify_to_cisco_webex - Installed console script (underscore name):
notify_to_cisco_webex— installed when you create a console-script entry with this name - Installed console script (hyphenated name):
notify-to-cisco-webex— the hyphenated command is provided by the package's console script entry (recommended for shell ergonomics)
Examples
Run via python -m:
python -m notify_to_cisco_webex -t "$WEBEX_ACCESS_TOKEN" -r "ROOM_ID" -m "Hello from -m" --file ./image.png
Run via direct module path:
python -m notify_to_cisco_webex.notify_to_cisco_webex -t "$WEBEX_ACCESS_TOKEN" -r "ROOM_ID" -m "Hello from direct module" --file ./image.png
Run via installed underscore console script (after pip install . or pip install -e .):
notify_to_cisco_webex -t "$WEBEX_ACCESS_TOKEN" -r "ROOM_ID" -m "Hello from underscore script" --file ./image.png
Run via installed hyphenated console script (after pip install . or pip install -e .):
notify-to-cisco-webex -t "$WEBEX_ACCESS_TOKEN" -r "ROOM_ID" -m "Hello from hyphenated script" --file ./image.png
CLI options
-t, --token— Webex access token (overrides env/.env)-r, --room-id— Room ID to send the message to-e, --to-email— Recipient email address (used when room id is not set)-m, --message— Message body text-f, --format— Message format,textormarkdown(default: Markdown)--timeout— HTTP request timeout in seconds (default: 10.0)--no-verify— Disable SSL certificate verification (flag)-v, --verbose— Enable verbose logging (flag)-p, --proxy— HTTP proxy URL--file— Attach a file. This option can be specified multiple times to attach multiple files (note: one file per Webex message)
CLI output:
- Printed JSON is pretty-printed for human readability when the operation succeeds.
- On error, the CLI prints a JSON object containing an
errorkey and exits with a non-zero status.
Examples
Send a simple message using environment variables:
export WEBEX_ACCESS_TOKEN="TOKEN"
export WEBEX_ROOM_ID="ROOM_ID"
python -m notify_to_cisco_webex --message "Hello"
Send multiple files (the message is included in the first message only):
notify-to-cisco-webex --token "TOKEN" --room-id "ROOM_ID" \
--message "Here are the files" --file ./1.jpg --file ./2.pdf
Testing
Run the automated tests using pytest:
python -m pip install -e '.[dev]'
pytest -q
Project structure highlights
notify_to_cisco_webex/notify_to_cisco_webex.py— Main implementation (contains theWebexclass and amain()CLI entry).tests/— pytest test cases.
Error handling
- The module raises
WebexErrorfor invalid configuration, file errors, HTTP errors, and non-JSON responses. - The CLI prints error information as JSON and returns a non-zero exit code on failures.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notify_to_cisco_webex-0.0.3.tar.gz.
File metadata
- Download URL: notify_to_cisco_webex-0.0.3.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4361d235e06d01f98dfd643606420049bebbfc9bf7a7edf9aa17c8704799ced
|
|
| MD5 |
334d102ae19357838476f729db622319
|
|
| BLAKE2b-256 |
6773ecff089378fbadebadad373c0084fbc390ef0123e9959cdfc77513089db3
|
File details
Details for the file notify_to_cisco_webex-0.0.3-py3-none-any.whl.
File metadata
- Download URL: notify_to_cisco_webex-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4789d060728962f07a80048a3f931217d5fac2816742d2afdd5df8504bc014b7
|
|
| MD5 |
073569d20c935f48f6d21fdb7233b7e7
|
|
| BLAKE2b-256 |
0b8da18ba1c883ba0dfb7ad30291687ec98b71047f6315fcc27bcde952feb720
|