OTP Message Extractor for Python
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
Release files for otp-message-extractor 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| otp_message_extractor-0.1.0.tar.gz | 8.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| otp_message_extractor-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / otp_message_extractor-0.1.0.tar.gz
| Download URL | otp_message_extractor-0.1.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fdbb05cbe0453af28346a531a45f07e6b2e2e983bf92d0177569b5bb4ae0a6f
|
|
BLAKE2b-256 checksum How to use checksums |
287ab57830441c3c34bd69f0d66611175bc90e7a5eececca28d9122eadae71a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / otp_message_extractor-0.1.0-py3-none-any.whl
| Download URL | otp_message_extractor-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
225055896eb308e51eded555045070d6070fa39b117fe89711b192436ebb2db7
|
|
BLAKE2b-256 checksum How to use checksums |
eb529cb23cd2ce4caa87a724220cbbc65eb3b21ce9fdaccf6f2be2ff5b654d1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency log