Skip to main content

A Python package for parsing transaction SMS messages into structured transaction dictionaries

Project description

Transaction SMS Parser

A Python package for parsing transaction SMS messages into structured transaction dictionaries using AI.

Features

  • Parse transaction SMS messages from various banks
  • Extract transaction details like amount, type, payee/payer, category
  • Configurable accounts and categories
  • Uses AI (Ollama) for intelligent parsing

Installation

From PyPI (once published)

pip install txn-msg-parser

From source

git clone https://github.com/yourusername/txn_msg_parser.git
cd txn_msg_parser
pip install -e .

Requirements

  • Python 3.8+
  • Ollama installed and running locally (see Ollama installation)
  • Ollama model: deepseek-r1:8b (or configure your own)

The package automatically installs the Python ollama library as a dependency.

Usage

Basic Example

from txn_msg_parser import TextParser, TxnText

# Initialize the parser with your bank accounts
accounts = ["HDFCBK", "SBIUPI"]
parser = TextParser(accounts=accounts)

# Create a transaction text object
txn_text = TxnText()
txn_text.sender = "HDFCBK-S(smsft)"
txn_text.text = "Sent Rs.437.00 From HDFC Bank A/C *5232 To BLINKIT COMMERCE PRIVATE LIMITED On 21/10/25"
txn_text.date = "2025-10-21 21:08:15"
txn_text.type = "sms"
txn_text.id = "unique-id"

# Parse the transaction
txn = parser.parse_text(txn_text)

# Access transaction details
print(f"Account: {txn.account}")
print(f"Amount: {txn.amount}")  # Amount in paise (multiplied by 100)
print(f"Type: {txn.txn_type}")  # 'debit' or 'credit'
print(f"Payee: {txn.payee}")
print(f"Category: {txn.category}")

Batch Processing

from txn_msg_parser import TextParser, TxnText

accounts = ["HDFCBK", "SBIUPI"]
parser = TextParser(accounts=accounts)

# Parse multiple messages
texts = [txn_text1, txn_text2, txn_text3]
transactions = parser.parse_texts(texts)

for txn in transactions:
    print(f"{txn.date}: {txn.amount} - {txn.category}")

Custom Categories

from txn_msg_parser import TextParser

custom_categories = ["Salary", "Rent", "Groceries", "Entertainment", "Utilities"]
accounts = ["HDFCBK", "SBIUPI"]

parser = TextParser(accounts=accounts, categories=custom_categories)

Configuration

Default Model

The package uses deepseek-r1:8b by default. You can change this:

parser = TextParser(accounts=accounts, model="your-ollama-local-model")

Default Categories

Default categories include: ["Salary", "EMI", "Food", "Travel", "Bills", "Shopping"]

Output Format

The Txn object contains:

  • account: Bank account identifier
  • amount: Transaction amount in paise (cents)
  • txn_type: "debit" or "credit"
  • payee: Recipient of payment (for debit transactions)
  • payer: Sender of payment (for credit transactions)
  • category: Transaction category
  • full_text: Original SMS text
  • date: Transaction date
  • id: Unique transaction identifier

Development

Setup Development Environment

git clone https://github.com/yourusername/txn_msg_parser.git
cd txn_msg_parser
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e .

Running Tests

python test.py

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

txn_msg_parser-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

txn_msg_parser-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: txn_msg_parser-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for txn_msg_parser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86095d515ca97b197aec4b3cabd8f9d5cc9825329ae240a111d15328ec6a78c6
MD5 ce79b75df7a7cc15b350d14fb1738b94
BLAKE2b-256 dc13f0a63cce7cce64eaea49ec58c92160d6c19cc032cc22b07471f211209494

See more details on using hashes here.

File details

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

File metadata

  • Download URL: txn_msg_parser-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for txn_msg_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eca75a86d0ede255c96abe462d33020fb103815e92c13adde382bab25f9b24a6
MD5 8e0951df00054379264f0fd3cfe9863e
BLAKE2b-256 29fb58ba628bf1ba8ac7d7cdcb5091e2f10855e1a11e6545c29194fb7b32506c

See more details on using hashes here.

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