Skip to main content

philiprehberger-type-parse

Tests PyPI version Last updated

philiprehberger-type-parse

Parse strings into Python types intelligently — booleans, numbers, dates, datetimes, UUIDs, filesizes, None, lists.

Installation

pip install philiprehberger-type-parse

Usage

from philiprehberger_type_parse import parse

parse("true")        # True
parse("42")          # 42
parse("3.14")        # 3.14
parse("2026-03-15")  # datetime.date(2026, 3, 15)
parse("none")        # None
parse("hello")       # "hello"

Boolean Parsing

from philiprehberger_type_parse import parse_bool

parse_bool("yes")    # True
parse_bool("off")    # False
parse_bool("1")      # True

Number Parsing

from philiprehberger_type_parse import parse_number

parse_number("1,234")     # 1234
parse_number("$19.99")    # 19.99
parse_number("50%")       # 50

Date Parsing

from philiprehberger_type_parse import parse_date

parse_date("2026-03-15")              # datetime.date(2026, 3, 15)
parse_date("15.03.2026", dayfirst=True)  # datetime.date(2026, 3, 15)
parse_date("March 15, 2026")          # datetime.date(2026, 3, 15)

Datetime Parsing

from philiprehberger_type_parse import parse_datetime

parse_datetime("2026-03-16 14:30:00")          # datetime(2026, 3, 16, 14, 30)
parse_datetime("2026-03-16T14:30:00Z")         # datetime(2026, 3, 16, 14, 30, tzinfo=UTC)
parse_datetime("2026-03-16T14:30:00+02:00")    # datetime with +02:00 offset
parse_datetime("Mar 16, 2026 2:30 PM")         # datetime(2026, 3, 16, 14, 30)

Time Parsing

from philiprehberger_type_parse import parse_time

parse_time("14:30")             # time(14, 30)
parse_time("2:30 PM")           # time(14, 30)
parse_time("14:30:00")          # time(14, 30)
parse_time("14:30:00.123456")   # time(14, 30, 0, 123456)

UUID Parsing

from philiprehberger_type_parse import parse_uuid

parse_uuid("550e8400-e29b-41d4-a716-446655440000")    # UUID('550e8400-...')
parse_uuid("550e8400e29b41d4a716446655440000")         # UUID without hyphens
parse_uuid("{550e8400-e29b-41d4-a716-446655440000}")   # UUID with braces

Bytes / Filesize Parsing

from philiprehberger_type_parse import parse_bytes

parse_bytes("1.5 GB")     # 1500000000 (SI, base 1000)
parse_bytes("1.5 GiB")    # 1610612736 (IEC, base 1024)
parse_bytes("500 MB")     # 500000000
parse_bytes("1024 KB")    # 1024000

List Parsing

from philiprehberger_type_parse import parse_list

parse_list("a, b, c")                        # ["a", "b", "c"]
parse_list("x|y|z", separator="|")           # ["x", "y", "z"]
parse_list("1, true, hello", coerce=True)    # [1, True, "hello"]
parse_list("42, 3.14, none", coerce=True)    # [42, 3.14, None]

Batch Parsing

Parse a list of strings in one call. Pass target_type to coerce every value to a specific type instead of relying on auto-detection.

from philiprehberger_type_parse import parse_many

parse_many(["1", "true", "2026-03-15"])
# [1, True, datetime.date(2026, 3, 15)]

parse_many(["1", "2", "3"], target_type=int)
# [1, 2, 3]

parse_many(["yes", "no", "on"], target_type=bool)
# [True, False, True]

API

Function / Class Description
parse(value) Auto-detect type: None, bool, int, float, UUID, datetime, date, or str
parse_many(values, target_type=None) Batch parse a list of strings, optionally coerced to a single target type
parse_bool(value) Parse true/yes/1/on/y or false/no/0/off/n
parse_number(value) Parse int or float with commas, currency, percentages
parse_date(value, *, dayfirst=False) Parse common date formats into datetime.date
parse_datetime(value, *, dayfirst=False) Parse date-time strings with optional timezone into datetime.datetime
parse_time(value) Parse time strings (24h, 12h AM/PM) into datetime.time
parse_uuid(value) Parse UUID strings (with/without hyphens/braces) into uuid.UUID
parse_bytes(value) Parse filesize strings (KB, MB, GB, KiB, MiB, GiB, etc.) to bytes
parse_list(value, *, separator=",", coerce=False) Split into trimmed, non-empty strings; optionally auto-detect types

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

⭐ Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Metadata

Release files for philiprehberger-type-parse 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for philiprehberger-type-parse 0.3.0
File Size Uploaded Provenance Actions
philiprehberger_type_parse-0.3.0.tar.gz 202.8 kB Without provenance Details for philiprehberger_type_parse-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for philiprehberger-type-parse 0.3.0
File Interpreter ABI Platform Actions
philiprehberger_type_parse-0.3.0-py3-none-any.whl Python 3 none any Details for philiprehberger_type_parse-0.3.0-py3-none-any.whl

Total release size: 210.5 kB

Release files / philiprehberger_type_parse-0.3.0.tar.gz

Download URL philiprehberger_type_parse-0.3.0.tar.gz
Size 202.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b589c1f1b1253dd57168e8cd4094e28374df4203ec5f6c7c2d9d9eef0069e9f9
BLAKE2b-256 checksum
How to use checksums
4331eaa7273adbd2337975a767e9b7eecfd4271782826da7534e655fc24f9f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / philiprehberger_type_parse-0.3.0-py3-none-any.whl

Download URL philiprehberger_type_parse-0.3.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
219c06130335531363ad9f870d436ac3e25477a2cdfa5da168dac9ebc60ec234
BLAKE2b-256 checksum
How to use checksums
a5a2402aacf4f5319d5034bcdf07316182551d19a70c11f134349ca3f23643f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for philiprehberger-type-parse 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page