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.4.tar.gz (4.1 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.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_type_parse-0.1.4.tar.gz
Algorithm Hash digest
SHA256 85aa8ec887b6c75d8de01b8b02279240cc647f697ee27b3cdf227df0babde069
MD5 013eae6f48ce82072ddfbc65fbaacd95
BLAKE2b-256 c35fa44c5f8f0bf0095b15ef2ff5c9f67f878dc31f6d936caf3d6dbb70e19d9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_type_parse-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cdccfe49addce9271563d358590f1288e08dfbc4207ac16080b238665c55af81
MD5 e485975ab6eecfa965a8f75f911b22ae
BLAKE2b-256 fd0b2a669059f96e22fe0d009ad3b6d333e1d33e20f7b83349088038bbb75695

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