Skip to main content

A Python library for monitoring and extracting iMessage data with real-time capabilities

Project description

iMessage Monitor

A Python library for monitoring and extracting iMessage data with real-time capabilities and beautiful terminal display.

Features

  • = Real-time monitoring of incoming iMessages
  • =� Pretty-printed chat bubbles with proper left/right alignment
  • <� Sticker and reaction support with emoji display
  • =� ASCII art generation for image attachments (optional)
  • =� Attachment handling including HEIC conversion
  • =� Outbound messaging via AppleScript or Shortcuts
  • =� Safe database access with read-only mode

Requirements

  • macOS only (requires access to Messages database)
  • Python 3.11+
  • Full Disk Access permission for terminal/IDE

Installation

pip install imessage-monitor

or

uv add imessage-monitor

Quick Start

Real-time Monitoring

from imessage_monitor import iMessageMonitor
from imessage_monitor.display import pretty_print_bubble

def handle_message(message):
    """Handle new messages with pretty printing."""
    print(pretty_print_bubble(message, show_ascii_art=True))

# Start monitoring
monitor = iMessageMonitor()
monitor.start(message_callback=handle_message)

# Keep running (in practice, you'd run this in an async loop)
input("Press Enter to stop...")
monitor.stop()

Message Retrieval

from imessage_monitor import iMessageMonitor, to_json

# Get recent messages
monitor = iMessageMonitor()
messages = monitor.get_recent_messages(limit=50)

# Convert to JSON
json_data = to_json(messages)
print(json_data)

Sending Messages

from imessage_monitor import ImessageOutbound

# Send via AppleScript
outbound = ImessageOutbound()
success = outbound.send_message_applescript("+1234567890", "Hello!")

# Send attachment
success = outbound.send_attachment_applescript("+1234567890", "/path/to/file.jpg")

Display Options

The library provides three pretty-print formats:

Chat Bubbles

from imessage_monitor.display import pretty_print_bubble

# Basic bubble (no ASCII art)
print(pretty_print_bubble(message))

# With ASCII art for images
print(pretty_print_bubble(message, show_ascii_art=True))

Reactions

from imessage_monitor.display import pretty_print_reaction

print(pretty_print_reaction(message))  # Shows d, =M, =, etc.

Stickers

from imessage_monitor.display import pretty_print_sticker

print(pretty_print_sticker(message, show_ascii_art=True))

Data Conversion

from imessage_monitor import to_json, to_toml

# Convert messages to different formats
json_str = to_json(messages)
toml_str = to_toml(messages)

# Save to files
to_json(messages, "messages.json")
to_toml(messages, "messages.toml")

Configuration

The library uses sensible defaults but can be configured:

from imessage_monitor.config import Config

# Create custom config
config = Config.default()
config.monitoring.poll_interval_seconds = 1  # Faster polling

monitor = iMessageMonitor(config_path="path/to/config.toml")

Permissions

Required: Full Disk Access

  1. Open System PreferencesSecurity & PrivacyPrivacy
  2. Select Full Disk Access
  3. Add your terminal application (Terminal.app, iTerm2, etc.)
  4. Add your IDE if running from there (VS Code, PyCharm, etc.)

Optional: Shortcuts (for outbound messaging)

For Shortcuts-based messaging, create these shortcuts in the Shortcuts app:

  • "Send Message" - Not Yet Implemented
  • "Send Attachment" - Not Yet Implemented

Platform Support

  • macOS: Supported
  • Windows/Linux: Not supported L (requires macOS Messages database)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: pytest
  5. Submit a pull request

Troubleshooting

"Database not found" error

  • Ensure you're running on macOS
  • Check Full Disk Access permissions
  • Verify Messages app has been used at least once

"Permission denied" error

  • Add Full Disk Access for your terminal/IDE
  • Restart terminal after adding permissions

ASCII art not showing

  • Ensure ascii-magic is installed
  • Enable with show_ascii_art=True parameter
  • Check image file accessibility

Examples

See example_usage.py for a complete real-time monitoring application.

Security Note

This library accesses your Messages database in read-only mode for monitoring. It does not modify or delete any messages. Outbound messaging requires explicit function calls and uses standard macOS APIs.

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

imessage_monitor-0.1.0.tar.gz (62.4 kB view details)

Uploaded Source

Built Distribution

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

imessage_monitor-0.1.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file imessage_monitor-0.1.0.tar.gz.

File metadata

  • Download URL: imessage_monitor-0.1.0.tar.gz
  • Upload date:
  • Size: 62.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for imessage_monitor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8600c55aa0f184ac5bee1e28a9e34bc96ce9ed6667a7c78a79397cae42bb7074
MD5 4cdbf016601938888254043a96b32226
BLAKE2b-256 e64324ec878ab61bbd4cae7808ec95424ec72b3bcb48b458d6fe465d354e05d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for imessage_monitor-0.1.0.tar.gz:

Publisher: publish.yml on Brynhild-CHale/imessage_monitor

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

File details

Details for the file imessage_monitor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for imessage_monitor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cde506aacf8fafdc339f63b196a6121c7222407f92afdb1748107073eae659d
MD5 018be6bbd6a5ab25607e598b2bd716cb
BLAKE2b-256 ca6cc9674b31b5bd6c26d53673006cb3026695247ee7e19eb47aa8cf5a86130a

See more details on using hashes here.

Provenance

The following attestation bundles were made for imessage_monitor-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Brynhild-CHale/imessage_monitor

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