Skip to main content

Parse strings into Python types intelligently — booleans, numbers, dates, None, lists

Project description

philiprehberger-type-parse

Tests PyPI version License

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

Install

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)

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"]

API

Function Description
parse(value) Auto-detect type: None, bool, int, float, date, or str
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_list(value, *, separator=",") Split into trimmed, non-empty strings

Development

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

License

MIT

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

philiprehberger_type_parse-0.1.5.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_type_parse-0.1.5-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_type_parse-0.1.5.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_type_parse-0.1.5.tar.gz
Algorithm Hash digest
SHA256 974d3f088e59353703336c9398165bc606d713e8641c0007f3a9167b7ccd4e49
MD5 d12f6db86e75caf77c21c554d1676376
BLAKE2b-256 305d858d1ff1566c671b0b1cd0e7586e7c43e3d25bb96643ec54b7084b5a0b23

See more details on using hashes here.

File details

Details for the file philiprehberger_type_parse-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_type_parse-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b8216da0c0e526133d37970c2adca10e2091534523052ae331ba235520b60443
MD5 b0dbf8f21e942fa47dbd28c51ca5c89d
BLAKE2b-256 f914dc988b1726d667dad8350f41a509c5d4895f16fd465cfd3a368b1201372a

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