Skip to main content

Shared enums and optional PostgreSQL helpers for email workflows

Project description

wr-common-lib

Shared enums and optional PostgreSQL helpers for the email table.

PyPI wr-common-lib
import wr_common_lib

Requires Python 3.12+.

Install

pip install wr-common-lib
pip install "wr-common-lib[db]"   # adds async-db-tools

Package layout

src/wr_common_lib/
├── __init__.py          # __version__
└── email/
    ├── __init__.py      # public exports
    ├── constants.py     # MailFlow, MailStatus
    └── db_oper.py       # EmailDbOper ([db] extra)

Enums

MailFlow and MailStatus are StrEnum values aligned with PostgreSQL mail_flow / mail_status.

from wr_common_lib.email import MailFlow, MailStatus

MailFlow.OUTBOUND
MailStatus.PENDING.value
MailStatus.SENT.is_terminal

Status flows

Outbound:  PENDING → SENT | FAILED;webhook → DELIVERED | BOUNCED
Inbound:   RECEIVED → PARSED | PARSE_FAILED

EmailDbOper

Requires the [db] extra and a async-db-tools PostgresPool.

EmailDbOper is lazy-imported: from wr_common_lib.email import MailStatus does not require async-db-tools.

from wr_common_lib.email import EmailDbOper, MailFlow, MailStatus, get_email_content_hash

db_oper = EmailDbOper(pool)

task = {
    "imo": 1234567,
    "voyage_id": "...",
    "mail_from": "ship@example.com",
    "to": "inbox@example.com",
    "cc": "",
    "subject": "...",
    "content": "...",
    "attachments": [],
    "content_hash": get_email_content_hash(...),  # optional
}

email_id = await db_oper.insert_email(task, MailFlow.INBOUND, MailStatus.RECEIVED)
await db_oper.update_status(email_id, MailStatus.SENT)
await db_oper.update_parsed_data(email_id, {"key": "value"})

Inbound and outbound use the same fields (to, cc, subject, content, attachments). DB columns remain mail_to / mail_cc.

Dependencies

install brings in
wr-common-lib
wr-common-lib[db] async-db-tools

Your application still owns the database URL and pool lifecycle.

Development

pip install -e ".[db]"

uv version 0.1.2          # bump before release
export UV_PUBLISH_TOKEN=pypi-...
uv build && uv publish

PyPI does not allow re-uploading the same version; always bump the version for a new release.

License

MIT — see LICENSE.

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

wr_common_lib-0.1.4.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

wr_common_lib-0.1.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file wr_common_lib-0.1.4.tar.gz.

File metadata

  • Download URL: wr_common_lib-0.1.4.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for wr_common_lib-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b8a871ee22cdf5406e757940e67e98b3d1a4de3a9a6bf935a5a8e22506cebde9
MD5 c41c1743215bab31ece5d0bdcc106e02
BLAKE2b-256 1c5fa1856ec8d09ef7574fb68df2f61929f6c956952ddd06913f65678e5bdfa5

See more details on using hashes here.

File details

Details for the file wr_common_lib-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: wr_common_lib-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for wr_common_lib-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e9b6eca4fa6369fb985a07e5f6876a52e00b955a7ac7fcdc731c550fd2c59eea
MD5 a640383efa80af223ab7b2a174dd60a3
BLAKE2b-256 3d52bbe4b6a79d03890b01af82958f29e213cc24bcbe36fa968070e90277282e

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