Skip to main content

Very fast Python library for .eml files parsing.

Project description

fast_mail_parser

Test PyPI version Downloads

fast_mail_parser is a Python library for .eml files parsing. The main benefit is a performance: the library is much faster than python implementations.

Based on mailparse library using pyo3.

Benchmark

 -------------------------------------------------------------------------------------------- benchmark: 2 tests -------------------------------------------------------------------------------------------
Name (time in ms)                              Min                Max               Mean            StdDev             Median               IQR            Outliers       OPS            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test__fast_mail_parser___parse_message      1.8136 (1.0)       1.8938 (1.0)       1.8426 (1.0)      0.0176 (1.0)       1.8465 (1.0)      0.0277 (1.0)         180;0  542.7141 (1.0)         450           1
test__mail_parser___parse_message          14.5583 (8.03)     15.8571 (8.37)     15.0264 (8.16)     0.2368 (13.49)    14.9702 (8.11)     0.2887 (10.42)         5;1   66.5495 (0.12)         32           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

Installation

Use the package manager pip to install fast_mail_parser.

pip install fast-mail-parser

Usage

import sys
from fast_mail_parser import parse_email, ParseError

with open('message.eml', 'r') as f:
    message_payload = f.read()

try:
    email = parse_email(message_payload)
except ParseError as e:
    print("Failed to parse email: ", e)
    sys.exit(1)

print(email.subject)
print(email.date)
print(email.text_plain)
print(email.text_html)
print(email.headers)

for attachment in email.attachments:
    print(attachment.mimetype)
    print(attachment.content)
    print(attachment.filename)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

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

fast_mail_parser-0.2.5.tar.gz (413.8 kB view hashes)

Uploaded Source

Built Distributions

fast_mail_parser-0.2.5-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl (429.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ x86-64

fast_mail_parser-0.2.5-cp310-none-win_amd64.whl (337.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

fast_mail_parser-0.2.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (427.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

fast_mail_parser-0.2.5-cp310-cp310-macosx_10_7_x86_64.whl (382.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

fast_mail_parser-0.2.5-cp39-none-win_amd64.whl (337.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

fast_mail_parser-0.2.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (427.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

fast_mail_parser-0.2.5-cp39-cp39-macosx_10_7_x86_64.whl (382.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

fast_mail_parser-0.2.5-cp38-none-win_amd64.whl (338.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

fast_mail_parser-0.2.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (427.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

fast_mail_parser-0.2.5-cp37-none-win_amd64.whl (338.0 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

fast_mail_parser-0.2.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (427.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page