A lightweight Python toolkit to parse .eml files and export to JSON, CSV, and more.
Project description
๐ง EmailParser
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
-
Fork the repository and create a feature branch.
-
Install dev dependencies:
pip install -r dev-requirements.txt
-
Run tests locally to ensure nothing breaks:
pytest -v
- (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.
- ๐ Report Bugs
- ๐ฑ Request Features
- ๐ Submit Pull Requests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b21aff4c516498c60f48a8a3e5eb7bc7f768dc262c0069f84e7ce7c19b3d58f3
|
|
| MD5 |
d374d87d1602ec48974c6c27cad78103
|
|
| BLAKE2b-256 |
26e178ead7b705da9ae926c263a6124efab65ac56b4407f2a111605028021435
|
File details
Details for the file emailparserandsorting-0.1.3-py3-none-any.whl.
File metadata
- Download URL: emailparserandsorting-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a4a4f19e943e96decb9f9eab25b47bed448d5091d2d9e5a63f9d1d9cc12aa75
|
|
| MD5 |
f740c58dcccb5894167d054e835b1b95
|
|
| BLAKE2b-256 |
9f0e24bcccf2c8b61465b0249bbdfe12900be41ae40075c47a281dc80ad12f80
|