Skip to main content

str2type

Convert the string representation of a Python type to its native type.

https://travis-ci.org/geowurster/str2type.svg?branch=master https://coveralls.io/repos/geowurster/str2type/badge.svg?branch=master

Why?

When building commandline utilities the syntax --arg key=val is useful, especially when key and val will be used as Class(key=val) internally. This module was built specifically to be used with the CLI framework click, and the included extensions play nicely, but the str2type.str2type() function can be used elsewhere.

Examples

See the examples directory for click integration examples. Everything else is primarily handled by a single function:

>>> from str2type import str2type
>>> print(str2type("1.23"))
1.23
>>> print(str2type("1.")
1.0
>>> print(str2type(".2"))
0.2
>>> print(str2type("None"))
None
>>> print(str2type('String'))
'String'

Supported Types

Only the standard builtin Python types plus JSON strings are supported:

  • int

  • float

  • None

  • True

  • False

  • JSON

Installing

Via pip:

$ pip install str2type

From master branch:

$ git clone https://github.com/geowurster/str2type
$ cd str2type
$ pip install .

Developing

Install:

$ pip install virtualenv
$ git clone https://github.com/geowurster/str2type
$ cd str2type
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements-dev.txt -e .
$ nosetests --with-coverage
$ pep8 --max-line-length=95 str2type

Metadata

Release files for str2type 0.4.1

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

Source distribution (sdist)

Source distribution for str2type 0.4.1
File Size Uploaded
str2type-0.4.1.tar.gz 7.2 kB Details

Release files / str2type-0.4.1.tar.gz

Download URL str2type-0.4.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f0682f079c225ff88006b12fa37f64e121c2b9e2d538a4611e4ef4a3ef982c05
BLAKE2b-256 checksum
How to use checksums
3028cf1f21ab9e42161fa61298b39ab34b4c7882e680424739484a1380b61d5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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