Skip to main content

A lightweight Python toolkit to parse .eml files and export to JSON, CSV, and more.

Project description

๐Ÿ“ง EmailParser

Tests PyPI Python Versions Coverage License

EmailParser is a lightweight Python library and CLI tool for extracting structured data from emails and exporting it in useful formats. Itโ€™s designed for developers, researchers, and businesses who want quick access to parsed email content without heavy dependencies. Perfect for automation workflows, or one off email analysis.

๐Ÿš€ Features

  • Parse raw email files (.eml) into structured objects
  • Export results (CSV, JSON, etc.)
  • Simple CLI for one-line parsing
  • Extendable with custom exporters
  • Includes tests to build trust and ensure reliability

๐Ÿ“‚ Project Structure

emailparser/
โ”œโ”€โ”€ emailparser/ # Core source code
โ”‚ โ”œโ”€โ”€ cli.py # CLI entrypoint
โ”‚ โ”œโ”€โ”€ parser.py # Email parsing logic
โ”‚ โ”œโ”€โ”€ exporters.py # Export functionality
โ”‚ โ”œโ”€โ”€ pro_features.py # Premium / extra features
โ”‚ โ””โ”€โ”€ init.py
โ”‚
โ”œโ”€โ”€ tests/ # Unit tests
โ”‚ โ”œโ”€โ”€ test_cli.py
โ”‚ โ”œโ”€โ”€ test_parser.py
โ”‚ โ””โ”€โ”€ init.py
โ”‚
โ”œโ”€โ”€ dist/ # Build artifacts (wheel, tar.gz)
โ”œโ”€โ”€ release/ # Release-ready builds
โ”œโ”€โ”€ build_and_package.py # Build helper script
โ”œโ”€โ”€ pyproject.toml # Modern build configuration
โ”œโ”€โ”€ setup.py # Legacy packaging script
โ”œโ”€โ”€ setup.cfg # Config for setuptools/pytest/etc.
โ”œโ”€โ”€ requirements.txt # Dev/test dependencies
โ””โ”€โ”€ README.md # Documentation


๐Ÿ”ง Installation From PyPI (recommended for production)

$ pip install emailparser

From TestPyPI (for testing pre-releases)

$ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple emailparser

This tells pip to prefer TestPyPI for your package but fall back to the main PyPI index for dependencies.

From source:

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

โœ… Verify the Installation

After installing, you can confirm everything works by running the CLI:

$ emailparser --help

You should see the available subcommands (parse, extract) listed.

usage: emailparser [-h] {parse,extract} ...

Or try a quick parse:

$ emailparser parse sample.eml --export json

Python Library Usage

You can also use it directly as a Python library:

from emailparser import parser

Parse an .eml file

parsed = parser.parse_email("sample.eml") print(parsed["subject"], parsed["from"])

๐Ÿš€ Quickstart

You can use emailparser either from the command line (CLI) or directly as a Python library.

โšก CLI Usage

Parse a single email file

emailparser parse demo.eml

Parse multiple files at once

emailparser parse inbox/*.eml

๐Ÿ Library Usage

from emailparser import parser

Example email content

content = """From: alice@example.com To: bob@example.com Subject: Hello

This is a test email body. """

Save to a file

with open("demo.eml", "w", encoding="utf-8") as f: f.write(content)

Parse the .eml file

parsed = parser.parse_email("demo.eml")

print(parsed)

Output:

{ "subject": "Hello", "from": "alice@example.com", "to": "bob@example.com", "body": "This is a test email body." }

๐Ÿ’ป Usage

CLI

$ emailparser parse input.eml --export json

๐Ÿ“˜ Python API Example

from emailparser import parser

with open("sample.eml", "r", encoding="utf-8") as f:
    content = f.read()

parsed = parser.parse_email(content)
print(parsed["subject"], parsed["from"])

โœ… Running Tests We include tests to ensure stability and trust. Run them with:

$ pytest -v

๐Ÿ”ฌ Development & Testing

Clone and install dev dependencies:

$ pip install -r requirements-dev.txt

Run tests with coverage:

$ pytest --cov=emailparser --cov-report=term-missing

๐Ÿงน Cleaning Up Builds Sometimes old build artifacts, caches, or temporary files clutter the project.
We include a helper script cleanup.py that resets your workspace to a clean state.

Run:

python cleanup.py

This will remove:

Build artifacts (dist/, release/, .egg-info/)

Cache directories (pycache/, .pytest_cache/)

Coverage files (.coverage)

Temporary outputs (out.json, out.txt, etc.)

๐Ÿ‘‰ Use this before creating a new build or publishing to PyPI for a fresh start.

Releasing

This project supports both TestPyPI (for safe testing) and full PyPI releases.

Test Release

$ py release_test.py

Install and verify:

$ py -m pip install --index-url https://test.pypi.org/simple/ --no-deps emailparser $ py -m emailparser --help

Full Release

$ py release.py

After publishing, users can install with:

$ pip install emailparser

๐Ÿ“‚ Real-World Workflow: Parse a Folder into JSON + CSV import os, json, csv from emailparser import parser

inbox_dir = "inbox" results = []

for filename in os.listdir(inbox_dir): if filename.endswith(".eml"): parsed = parser.parse_email(os.path.join(inbox_dir, filename)) results.append(parsed)

with open("emails.json", "w", encoding="utf-8") as jf: json.dump(results, jf, indent=2)

with open("emails.csv", "w", newline="", encoding="utf-8") as cf: writer = csv.DictWriter(cf, fieldnames=["subject", "from", "to", "body"]) writer.writeheader() writer.writerows(results)

print(f"โœ… Parsed {len(results)} emails into emails.json and emails.csv")

๐Ÿ› ๏ธ Pro Features (Optional SaaS Hooks)

Some functionality (like advanced entity extraction) is reserved for Pro/SaaS usage.

emailparser extract sample.eml

๐Ÿ—บ๏ธ Roadmap

Attachments parsing

More output formats (Parquet, SQLite)

Built-in SaaS-ready API server

GUI desktop version for non-coders

๐Ÿ“œ License This project is licensed under the MIT License โ€“ see the LICENSE file for details.

๐Ÿค Contributing
Contributions are welcome!

How to Contribute

  1. Fork the repository and create a feature branch.

  2. Install dev dependencies:

    pip install -r dev-requirements.txt
    
  3. Run tests locally to ensure nothing breaks:

pytest -v
  1. (Optional but recommended) Run the cleanup script to reset the workspace before committing or opening a PR:
python cleanup.py

Guidelines

Please include tests for any new features.

Follow existing code style and structure.

Submit PRs with clear descriptions of changes.

Pull requests with improvements or new exporters are especially encouraged ๐Ÿš€

We love contributions that add parsers for new email formats or integrations with CRMs.

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

emailparserandsorting-0.1.3.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

emailparserandsorting-0.1.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file emailparserandsorting-0.1.3.tar.gz.

File metadata

  • Download URL: emailparserandsorting-0.1.3.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for emailparserandsorting-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b21aff4c516498c60f48a8a3e5eb7bc7f768dc262c0069f84e7ce7c19b3d58f3
MD5 d374d87d1602ec48974c6c27cad78103
BLAKE2b-256 26e178ead7b705da9ae926c263a6124efab65ac56b4407f2a111605028021435

See more details on using hashes here.

File details

Details for the file emailparserandsorting-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for emailparserandsorting-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9a4a4f19e943e96decb9f9eab25b47bed448d5091d2d9e5a63f9d1d9cc12aa75
MD5 f740c58dcccb5894167d054e835b1b95
BLAKE2b-256 9f0e24bcccf2c8b61465b0249bbdfe12900be41ae40075c47a281dc80ad12f80

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