Skip to main content

OTP Message Extractor for Python

PyPI version Python versions CI MIT License

Extract OTP, verification, security, 2FA, and MFA codes from Arabic or English SMS, email, and notification text.

otp-message-extractor is a tiny, dependency-free Python parser for 4–8 digit OTPs and mixed alphanumeric codes. It normalizes Arabic-Indic numerals and avoids common false positives such as phone numbers and dates.

from otp_message_extractor import extract_otp

extract_otp("Your verification code is 582914")
# {"code": "582914", "confidence": 0.98}

Python 3.9+ · Arabic + English · Fully typed · Zero runtime dependencies · No network requests

Installation

python -m pip install otp-message-extractor

Quick start

English verification code

from otp_message_extractor import extract_otp

result = extract_otp("Your verification code is 582914")
# {"code": "582914", "confidence": 0.98}

Arabic verification code

extract_otp("رمز التحقق الخاص بك هو ٥٨٢٩١٤")
# {"code": "582914", "confidence": 0.98}

Alphanumeric OTP

extract_otp("Your verification code is A8D-291")
# {"code": "A8D-291", "confidence": 0.96}

Ignore phone numbers and dates

extract_otp("Call +20 10 1234 5678")
# None

extract_otp("The appointment date is 2026-08-03")
# None

Select the OTP when other numbers are present

message = "Call +20 10 1234 5678 before 03/08/2026. Your code is 739201."
extract_otp(message)
# {"code": "739201", "confidence": 0.95}

Supported formats

Message or code type Example Result
4-digit PIN OTP: 4821 4821
6-digit verification code Your code is 582914 582914
8-digit security code Security code: 12345678 12345678
Arabic-Indic digits رمز التحقق ٥٨٢٩١٤ 582914
Eastern Arabic-Indic digits کد تایید ۱۲۳۴۵۶ 123456
Alphanumeric code Code: A8D-291 A8D-291
Structured date Date: 03/08/2026 None
Phone number Phone: +20 10 1234 5678 None

API

extract_otp(message)

Accepts a string and returns the strongest OTP candidate as a dictionary, or None when no sufficiently strong candidate exists.

from typing import Optional
from otp_message_extractor import OTPResult

result: Optional[OTPResult] = extract_otp(message)

The returned confidence is a deterministic heuristic score from 0 to 0.99; it is not a statistical probability. Non-string input raises TypeError.

For teams sharing examples with the JavaScript package, extractOTP is also exported as an alias. New Python code should prefer the Pythonic extract_otp name.

Common use cases

  • Extract verification codes in Python authentication services.
  • Highlight or copy OTPs in an SMS inbox or support dashboard.
  • Parse codes from email subjects, plain-text bodies, and notifications.
  • Authorized QA and end-to-end tests for sign-in and payment flows.
  • Virtual-number, temporary-number, and receive-SMS inbox interfaces.

This package only parses the message string your application supplies. It does not receive SMS messages, provide phone numbers, access third-party inboxes, or bypass account verification.

Temporary-number and receive-SMS integrations

The parser can power OTP highlighting and one-click copy experiences in authorized virtual-number or online SMS inbox products, similar to the code-extraction experience users expect from receive-SMS websites such as Receive SMS Live.

This project is independent and is not affiliated with, endorsed by, or connected to Receive SMS Live. Use it only with messages and systems you own or are authorized to process. Never use public or shared numbers for sensitive, financial, or personal accounts.

Python and JavaScript packages

Ecosystem Install Import
Python / PyPI pip install otp-message-extractor from otp_message_extractor import extract_otp
JavaScript / npm npm install otp-message-extractor import extractOTP from "otp-message-extractor"

The JavaScript package is available on npm, with source at fencercensor/otp-message-extractor.

العربية — استخراج كود التحقق في Python

مكتبة Python خفيفة ومن دون اعتماديات لاستخراج رمز التحقق أو كود التأكيد من رسائل SMS والبريد الإلكتروني والإشعارات باللغة العربية أو الإنجليزية.

from otp_message_extractor import extract_otp

extract_otp("كود التأكيد الخاص بك هو ٤٨٢١")
# {"code": "4821", "confidence": 0.93}

تدعم المكتبة الأكواد الرقمية من 4 إلى 8 أرقام، والأرقام العربية، والأكواد المختلطة مثل A8D-291، مع تجاهل صيغ أرقام الهاتف والتواريخ الشائعة. كل المعالجة محلية ولا يتم إرسال الرسالة أو الكود إلى أي خدمة خارجية.

Security and privacy

  • Do not log message bodies or extracted OTPs in production.
  • Treat OTPs as secrets and discard them immediately after verification.
  • Process only messages you are authorized to access.
  • The package runs locally and performs no network requests.

See SECURITY.md for vulnerability reporting.

Development

python -m pip install -e ".[dev]"
ruff check .
pytest
python -m build
twine check dist/*

Contributing

Bug reports, invented message examples, and pull requests are welcome. Never include a real phone number, OTP, or private message in an issue. See CONTRIBUTING.md.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otp_message_extractor-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

otp_message_extractor-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: otp_message_extractor-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for otp_message_extractor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1fdbb05cbe0453af28346a531a45f07e6b2e2e983bf92d0177569b5bb4ae0a6f
MD5 749e29e199b020d8bc985f4c8ad53715
BLAKE2b-256 287ab57830441c3c34bd69f0d66611175bc90e7a5eececca28d9122eadae71a6

See more details on using hashes here.

Provenance

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

Publisher: release.yml on fencercensor/otp-message-extractor-python

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

File details

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

File metadata

File hashes

Hashes for otp_message_extractor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 225055896eb308e51eded555045070d6070fa39b117fe89711b192436ebb2db7
MD5 29ac15b48f6b6f2088ae3890b72da324
BLAKE2b-256 eb529cb23cd2ce4caa87a724220cbbc65eb3b21ce9fdaccf6f2be2ff5b654d1d

See more details on using hashes here.

Provenance

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

Publisher: release.yml on fencercensor/otp-message-extractor-python

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