Skip to main content

Read Strings

Project description

readstr

Provides readstr, a function that can read a lot of different types from strings:

from readstr import readstr
import typing
import uuid

readstr('1,2,3', typing.Set[int])
readstr('foo=3,bar=10', typing.Dict[str, int])
readstr('vUfDOuQwRVavn3_QjMxp7Q', uuid.UUID)

Useful for reading arguments from command line arg, from environment variables, etc.

Extensible

from dataclasses import dataclass
from typing import List
from readstr import readstr, reads

@dataclass
class Path:
    path: str

@reads
def read_path(str_value: str) -> Path:
    return Path(str_value)

readstr('file://a,file://b', List[Path])

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

readstr-0.3.0.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

readstr-0.3.0-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page