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.1.tar.gz (8.2 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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: txn_msg_parser-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 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.1.tar.gz
Algorithm Hash digest
SHA256 fc053a248d9a2ced2bdaf84ff5da323a13b0786f8ced4311457d8d539b027e43
MD5 2cc649046734cd00061c06f5b93a9589
BLAKE2b-256 be868ba4415973cf6aea7fbbc61e4ced0369269d5fd8dcc6ca2760201c939c15

See more details on using hashes here.

File details

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

File metadata

  • Download URL: txn_msg_parser-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b9ca619cb9a29ac79403e5b4db3e6fa5ded8922068431267dfaa14dcc59f0c4
MD5 205bed93496baf304dc1ee38e20f4a06
BLAKE2b-256 9d5465769a74e47f2d5660f015f1afa9bbfe5d8b1d0e6abfc5825f041a17fd2f

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