parsetypes


Nameparsetypes JSON
Version 0.3.2 PyPI version JSON
download
home_page
SummaryParse serialised data to recover their original underlying types
upload_time2023-07-28 16:44:10
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMPL-2.0
keywords python str string types conversion
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # parsetypes

This Python package provides tools for parsing serialised data to recover their original underlying types.

[![](https://img.shields.io/badge/PyPI--inactive?style=social&logo=pypi)](https://pypi.org/project/parsetypes/) [![](https://img.shields.io/badge/GitHub--inactive?style=social&logo=github)](https://github.com/yushiyangk/parsetypes) [![](https://img.shields.io/badge/Documentation--inactive?style=social&logo=readthedocs)](https://parsetypes.gnayihs.uy/)

## Overview

The `TypeParser` class provides configurable type inference and parsing. This can be [initialised with different settings](https://parsetypes.gnayihs.uy/parsetypes.html#TypeParser.__init__) to, for example:
- allow `None` (null values) or not
- treat `inf` as either a float or a normal string
- give exact Decimal values instead of floats
- detect inline lists

## Install

```
pip install parsetypes
```

## Basic examples

Import parser:
```python
from parsetypes import TypeParser
```

Parse a single value:
```python
parser = TypeParser()
parser.parse("1.2")   # 1.2
parser.parse("true")  # True
parser.parse("")      # None
```

Parse a series so that it has a consistent type:
```python
parser = TypeParser()
parser.parse_series(["0", "1", "2"])         # [0, 1, 2]
parser.parse_series(["0", "1.2", ""])        # [0.0, 1.2, None]
parser.parse_series(["false", "true", ""])   # [False, True, None]
parser.parse_series(["false", "true", "2"])  # [0, 1, 2]
parser.parse_series(["1", "2.3", "abc"])     # ["1", "2.3", "abc"]
```

Parse a table so that each column is of a consistent type:
```python
parser = TypeParser()
table = parser.parse_table([
	["0", "3",   "false", "false", "7"],
	["1", "4.5", "true",  "true",  "8.9"],
	["2", "",    "",      "6",     "abc"],
]):
assert table == [
	[0, 3.0,  False, 0, "7"],
	[1, 4.5,  True,  1, "8.9"],
	[2, None, None,  6, "abc"],
]
```

The main contribution of this module lies in the [`infer_series()`](https://parsetypes.gnayihs.uy/parsetypes.html#TypeParser.infer_series) and [`infer_table()`](https://parsetypes.gnayihs.uy/parsetypes.html#TypeParser.infer_table) functions, which are also called by `parse_series()` and `parse_table()`.

## Issues

Found a bug? Please [report an issue](https://github.com/yushiyangk/parsetypes/issues), or, better yet, [contribute a bugfix](https://github.com/yushiyangk/parsetypes/blob/main/CONTRIBUTING.md).

## Changelog

This project follows [PEP 440](https://peps.python.org/pep-0440/) and [Semantic Versioning (SemVer)](https://semver.org/spec/v2.0.0.html). In addition to the guarantees specified by SemVer, for versions before 1.0, this project guarantees backwards compatibility of the API for patch version updates (0.<var>y</var>.<b><var>z</var></b>).

The recommended version specifier is <code>parsetypes ~= <var>x</var>.<var>y</var></code> for version 1.0 and later, and <code>parsetypes ~= <var>0</var>.<var>y</var>.<var>z</var></code> for versions prior to 1.0.

### 0.3.2

- Improved documentation

### 0.3.1

- Added the arguments `allow_negative` and `allow_sign` (both `True` by default) to <code><var>parser</var>.parse_int()</code>, for parity with <code><var>parser</var>.is_int()</code> which already had these arguments

### 0.3

- Made the previously public but undocumented instance variables of TypeParser that corresponded to the constructor arguments private instead
- Added public properties to TypeParser for accessing or modifying the same settings in a controlled manner

### 0.2.6

- Added `Nullable` to automatic imports via `from parsetypes import *` (previously only `TypeParser` and `reduce_types` were imported)

### 0.2.5

- Fixed documentation

### 0.2.4

- Added <code><var>parser</var>.convert()</code>

### 0.2.1, 0.2.2, 0.2.3

- Fixed documentation

### 0.2

- Added support for Python version 3.9; previously only 3.10 and 3.11 were supported

### 0.1.1

- Updated documentation

### 0.1

- Initial version

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "parsetypes",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "python,str,string,types,conversion",
    "author": "",
    "author_email": "Yu Shiyang <yu.shiyang@gnayihs.uy>",
    "download_url": "https://files.pythonhosted.org/packages/d5/56/05e218b3b91a46d7bd0d504b50667b66a70f4df3f78ca9be2225dd8a37cf/parsetypes-0.3.2.tar.gz",
    "platform": null,
    "description": "# parsetypes\r\n\r\nThis Python package provides tools for parsing serialised data to recover their original underlying types.\r\n\r\n[![](https://img.shields.io/badge/PyPI--inactive?style=social&logo=pypi)](https://pypi.org/project/parsetypes/) [![](https://img.shields.io/badge/GitHub--inactive?style=social&logo=github)](https://github.com/yushiyangk/parsetypes) [![](https://img.shields.io/badge/Documentation--inactive?style=social&logo=readthedocs)](https://parsetypes.gnayihs.uy/)\r\n\r\n## Overview\r\n\r\nThe `TypeParser` class provides configurable type inference and parsing. This can be [initialised with different settings](https://parsetypes.gnayihs.uy/parsetypes.html#TypeParser.__init__) to, for example:\r\n- allow `None` (null values) or not\r\n- treat `inf` as either a float or a normal string\r\n- give exact Decimal values instead of floats\r\n- detect inline lists\r\n\r\n## Install\r\n\r\n```\r\npip install parsetypes\r\n```\r\n\r\n## Basic examples\r\n\r\nImport parser:\r\n```python\r\nfrom parsetypes import TypeParser\r\n```\r\n\r\nParse a single value:\r\n```python\r\nparser = TypeParser()\r\nparser.parse(\"1.2\")   # 1.2\r\nparser.parse(\"true\")  # True\r\nparser.parse(\"\")      # None\r\n```\r\n\r\nParse a series so that it has a consistent type:\r\n```python\r\nparser = TypeParser()\r\nparser.parse_series([\"0\", \"1\", \"2\"])         # [0, 1, 2]\r\nparser.parse_series([\"0\", \"1.2\", \"\"])        # [0.0, 1.2, None]\r\nparser.parse_series([\"false\", \"true\", \"\"])   # [False, True, None]\r\nparser.parse_series([\"false\", \"true\", \"2\"])  # [0, 1, 2]\r\nparser.parse_series([\"1\", \"2.3\", \"abc\"])     # [\"1\", \"2.3\", \"abc\"]\r\n```\r\n\r\nParse a table so that each column is of a consistent type:\r\n```python\r\nparser = TypeParser()\r\ntable = parser.parse_table([\r\n\t[\"0\", \"3\",   \"false\", \"false\", \"7\"],\r\n\t[\"1\", \"4.5\", \"true\",  \"true\",  \"8.9\"],\r\n\t[\"2\", \"\",    \"\",      \"6\",     \"abc\"],\r\n]):\r\nassert table == [\r\n\t[0, 3.0,  False, 0, \"7\"],\r\n\t[1, 4.5,  True,  1, \"8.9\"],\r\n\t[2, None, None,  6, \"abc\"],\r\n]\r\n```\r\n\r\nThe main contribution of this module lies in the [`infer_series()`](https://parsetypes.gnayihs.uy/parsetypes.html#TypeParser.infer_series) and [`infer_table()`](https://parsetypes.gnayihs.uy/parsetypes.html#TypeParser.infer_table) functions, which are also called by `parse_series()` and `parse_table()`.\r\n\r\n## Issues\r\n\r\nFound a bug? Please [report an issue](https://github.com/yushiyangk/parsetypes/issues), or, better yet, [contribute a bugfix](https://github.com/yushiyangk/parsetypes/blob/main/CONTRIBUTING.md).\r\n\r\n## Changelog\r\n\r\nThis project follows [PEP 440](https://peps.python.org/pep-0440/) and [Semantic Versioning (SemVer)](https://semver.org/spec/v2.0.0.html). In addition to the guarantees specified by SemVer, for versions before 1.0, this project guarantees backwards compatibility of the API for patch version updates (0.<var>y</var>.<b><var>z</var></b>).\r\n\r\nThe recommended version specifier is <code>parsetypes ~= <var>x</var>.<var>y</var></code> for version 1.0 and later, and <code>parsetypes ~= <var>0</var>.<var>y</var>.<var>z</var></code> for versions prior to 1.0.\r\n\r\n### 0.3.2\r\n\r\n- Improved documentation\r\n\r\n### 0.3.1\r\n\r\n- Added the arguments `allow_negative` and `allow_sign` (both `True` by default) to <code><var>parser</var>.parse_int()</code>, for parity with <code><var>parser</var>.is_int()</code> which already had these arguments\r\n\r\n### 0.3\r\n\r\n- Made the previously public but undocumented instance variables of TypeParser that corresponded to the constructor arguments private instead\r\n- Added public properties to TypeParser for accessing or modifying the same settings in a controlled manner\r\n\r\n### 0.2.6\r\n\r\n- Added `Nullable` to automatic imports via `from parsetypes import *` (previously only `TypeParser` and `reduce_types` were imported)\r\n\r\n### 0.2.5\r\n\r\n- Fixed documentation\r\n\r\n### 0.2.4\r\n\r\n- Added <code><var>parser</var>.convert()</code>\r\n\r\n### 0.2.1, 0.2.2, 0.2.3\r\n\r\n- Fixed documentation\r\n\r\n### 0.2\r\n\r\n- Added support for Python version 3.9; previously only 3.10 and 3.11 were supported\r\n\r\n### 0.1.1\r\n\r\n- Updated documentation\r\n\r\n### 0.1\r\n\r\n- Initial version\r\n",
    "bugtrack_url": null,
    "license": "MPL-2.0",
    "summary": "Parse serialised data to recover their original underlying types",
    "version": "0.3.2",
    "project_urls": {
        "Documentation": "https://parsetypes.gnayihs.uy/",
        "Homepage": "https://github.com/yushiyangk/parsetypes",
        "Issues": "https://github.com/yushiyangk/parsetypes/issues"
    },
    "split_keywords": [
        "python",
        "str",
        "string",
        "types",
        "conversion"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "379df1c0dc0b26c90191f1e8016283ffec1ef3761b9035beb73213db23700e85",
                "md5": "2c701afbe4483b1809f7bbefef99f375",
                "sha256": "97f55acd9553136c464a846d636af05dce5ab96a44b11325b0b686e347298e4c"
            },
            "downloads": -1,
            "filename": "parsetypes-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2c701afbe4483b1809f7bbefef99f375",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 14274,
            "upload_time": "2023-07-28T16:44:08",
            "upload_time_iso_8601": "2023-07-28T16:44:08.684249Z",
            "url": "https://files.pythonhosted.org/packages/37/9d/f1c0dc0b26c90191f1e8016283ffec1ef3761b9035beb73213db23700e85/parsetypes-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d55605e218b3b91a46d7bd0d504b50667b66a70f4df3f78ca9be2225dd8a37cf",
                "md5": "aa9eb380d233492e53aed187fa9b6b50",
                "sha256": "82362496cf55db1e9a9ce5921fad2c553304375f2bd5f17964c29ff98d5e8b07"
            },
            "downloads": -1,
            "filename": "parsetypes-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "aa9eb380d233492e53aed187fa9b6b50",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 106277,
            "upload_time": "2023-07-28T16:44:10",
            "upload_time_iso_8601": "2023-07-28T16:44:10.872199Z",
            "url": "https://files.pythonhosted.org/packages/d5/56/05e218b3b91a46d7bd0d504b50667b66a70f4df3f78ca9be2225dd8a37cf/parsetypes-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-28 16:44:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yushiyangk",
    "github_project": "parsetypes",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "parsetypes"
}
        
Elapsed time: 0.09922s