Skip to main content

Convert a string representation of an int, float, None, True, False, or JSON to its native type. For None, True, and False, case is irrelevant.

Project description

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


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.


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"))
>>> print(str2type("1.")
>>> print(str2type(".2"))
>>> print(str2type("None"))
>>> print(str2type('String'))

Supported Types

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

  • int
  • float
  • None
  • True
  • False
  • JSON


Via pip:

$ pip install str2type

From master branch:

$ git clone
$ cd str2type
$ pip install .



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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for str2type, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size str2type-0.4.1.tar.gz (7.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page