Convert types in source data.


Keywords
types, rdf
License
MIT
Install
pip install typecast==0.3.3

Documentation

typecast

Build Status Coverage Status

This light-weight library contains a set of type converters commonly used to parse string-typed values into more specific types, such as numbers, booleans or dates. A typical use case might be converting values from HTTP query strings or CSV files.

The benefits of using this library include a well-tested handling of type conversions, e.g. for JSON Schema or JTS. Further, a consistent system of exceptions (catch ConverterError and all is forgiven) makes it easier to handle data errors.

Example usage

typecast can easily be included in many applications. A Python snippet using the library could look like this:

import typecast

type_name = 'date'
value = '2031-01-05'
converted = typecast.cast(type_name, value)
assert converted.year == 2031

other = typecast.stringify(type_name, converted)
assert value == other

The supported type names are:

  • string, text
  • number, integer
  • float
  • decimal
  • date
  • datetime
  • boolean, bool

Tests

The goal is to have a high-nineties test coverage, and to collect as many odd fringe cases as possible.

$ make test