latex2pydata


Namelatex2pydata JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryLoad data from LaTeX in Python literal format
upload_time2023-11-20 19:14:58
maintainer
docs_urlNone
author
requires_python>=3.7
licenseBSD 3-Clause License Copyright (c) 2023, Geoffrey M. Poore All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords deserialization latex python literal format
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # latex2pydata - load data from LaTeX in Python literal format

The latex2pydata Python package is designed to load data in
[Python literal format](https://docs.python.org/3/reference/lexical_analysis.html#literals)
that was saved to file by the
[latex2pydata LaTeX package](https://github.com/gpoore/latex2pydata_tex).
This allows data to be passed from [LaTeX](https://www.latex-project.org/) to
Python.

Raw data is loaded with
[`ast.literal_eval()`](https://docs.python.org/3/library/ast.html#ast.literal_eval).  This always yields either `dict[str,str]` or
`list[dict[str,str]]`.  Then data is postprocessed to apply any schemas and to unpack key paths.

* The LaTeX package allows schemas to be defined using Python type annotation
  syntax.  When a schema exists, string values are evaluated with
  `ast.literal_eval()`, and then the data type of each result is checked
  against the schema.

* All dict keys are required to match the regex `[A-Za-z_][0-9A-Za-z_]*`.
  Periods in keys are interpreted as key paths and indicate sub-dicts.  For
  example, the key path `main.sub` represents a key `main` in the main dict
  that maps to a sub-dict containing a key `sub`.


## Schema support

The current parser for Python type annotation syntax is basic and limits the
supported schema data types:

* Nested collection data types are only supported 2 levels deep.  So
  `list[list[int]]` is fine, but `list[list[list[int]]]` is not supported.

* Collection union types are not supported.  For example, `set[int]|list[int]`
  is not supported.  (Scalar union types such as `float|int` are supported.)

It is possible to work around these limitations by setting
`\pydatasetschemamissing{evalany}` on the LaTeX side.  This causes all values
without a schema definition to be evaluated with `ast.literal_eval()`, and
skips type checking for values that are not defined in the schema.

Currently, if a key path is used in defining a schema value or setting a
data value, then the same key path must be used in both the schema and the
data.  That is, schema validation is currently performed before key path
unpacking.

See the source code and the
[latex2pydata LaTeX package](https://github.com/gpoore/latex2pydata_tex)
documentation for additional details about schema support.


## Keys and key paths

Data is interpreted as Python literals.  Thus, there is no checking for
duplicate keys.  If a key is defined multiple times, later values replace
earlier values.  Similarly, there is no checking for duplicate keys during
key path unpacking.


## Usage

The package provides two functions for loading data:
* `load(<filehandle or pathlib.Path>, encoding='utf-8-sig')`
* `loads(<string>)`


## Tests

The latex2pydata Python package includes tests.  Additional tests are part
of the
[latex2pydata LaTeX package](https://github.com/gpoore/latex2pydata_tex).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "latex2pydata",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "deserialization,LaTeX,Python literal format",
    "author": "",
    "author_email": "\"Geoffrey M. Poore\" <gpoore@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6e/a5/af285da6d64c81f4e61a1be2619510ae58fca80990d9e7a1d689d9b570c6/latex2pydata-0.1.0.tar.gz",
    "platform": null,
    "description": "# latex2pydata - load data from LaTeX in Python literal format\r\n\r\nThe latex2pydata Python package is designed to load data in\r\n[Python literal format](https://docs.python.org/3/reference/lexical_analysis.html#literals)\r\nthat was saved to file by the\r\n[latex2pydata LaTeX package](https://github.com/gpoore/latex2pydata_tex).\r\nThis allows data to be passed from [LaTeX](https://www.latex-project.org/) to\r\nPython.\r\n\r\nRaw data is loaded with\r\n[`ast.literal_eval()`](https://docs.python.org/3/library/ast.html#ast.literal_eval).  This always yields either `dict[str,str]` or\r\n`list[dict[str,str]]`.  Then data is postprocessed to apply any schemas and to unpack key paths.\r\n\r\n* The LaTeX package allows schemas to be defined using Python type annotation\r\n  syntax.  When a schema exists, string values are evaluated with\r\n  `ast.literal_eval()`, and then the data type of each result is checked\r\n  against the schema.\r\n\r\n* All dict keys are required to match the regex `[A-Za-z_][0-9A-Za-z_]*`.\r\n  Periods in keys are interpreted as key paths and indicate sub-dicts.  For\r\n  example, the key path `main.sub` represents a key `main` in the main dict\r\n  that maps to a sub-dict containing a key `sub`.\r\n\r\n\r\n## Schema support\r\n\r\nThe current parser for Python type annotation syntax is basic and limits the\r\nsupported schema data types:\r\n\r\n* Nested collection data types are only supported 2 levels deep.  So\r\n  `list[list[int]]` is fine, but `list[list[list[int]]]` is not supported.\r\n\r\n* Collection union types are not supported.  For example, `set[int]|list[int]`\r\n  is not supported.  (Scalar union types such as `float|int` are supported.)\r\n\r\nIt is possible to work around these limitations by setting\r\n`\\pydatasetschemamissing{evalany}` on the LaTeX side.  This causes all values\r\nwithout a schema definition to be evaluated with `ast.literal_eval()`, and\r\nskips type checking for values that are not defined in the schema.\r\n\r\nCurrently, if a key path is used in defining a schema value or setting a\r\ndata value, then the same key path must be used in both the schema and the\r\ndata.  That is, schema validation is currently performed before key path\r\nunpacking.\r\n\r\nSee the source code and the\r\n[latex2pydata LaTeX package](https://github.com/gpoore/latex2pydata_tex)\r\ndocumentation for additional details about schema support.\r\n\r\n\r\n## Keys and key paths\r\n\r\nData is interpreted as Python literals.  Thus, there is no checking for\r\nduplicate keys.  If a key is defined multiple times, later values replace\r\nearlier values.  Similarly, there is no checking for duplicate keys during\r\nkey path unpacking.\r\n\r\n\r\n## Usage\r\n\r\nThe package provides two functions for loading data:\r\n* `load(<filehandle or pathlib.Path>, encoding='utf-8-sig')`\r\n* `loads(<string>)`\r\n\r\n\r\n## Tests\r\n\r\nThe latex2pydata Python package includes tests.  Additional tests are part\r\nof the\r\n[latex2pydata LaTeX package](https://github.com/gpoore/latex2pydata_tex).\r\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2023, Geoffrey M. Poore All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "Load data from LaTeX in Python literal format",
    "version": "0.1.0",
    "project_urls": {
        "changelog": "https://github.com/gpoore/latex2pydata_py/blob/master/CHANGELOG.md",
        "homepage": "https://github.com/gpoore/latex2pydata_py",
        "repository": "https://github.com/gpoore/latex2pydata_py"
    },
    "split_keywords": [
        "deserialization",
        "latex",
        "python literal format"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcb834117cdd4ec2b2f4a73eafe5739d0a505eb31fa85e97891b16f016f112f9",
                "md5": "e287d6f5afa585aacf40134a50969007",
                "sha256": "676a790d25faf19e3f52d6ce11805af9089ab896d21448a30ccf4fe6ca21afb4"
            },
            "downloads": -1,
            "filename": "latex2pydata-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e287d6f5afa585aacf40134a50969007",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 12128,
            "upload_time": "2023-11-20T19:14:57",
            "upload_time_iso_8601": "2023-11-20T19:14:57.403939Z",
            "url": "https://files.pythonhosted.org/packages/bc/b8/34117cdd4ec2b2f4a73eafe5739d0a505eb31fa85e97891b16f016f112f9/latex2pydata-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ea5af285da6d64c81f4e61a1be2619510ae58fca80990d9e7a1d689d9b570c6",
                "md5": "2cbf473e25b966c34632cdaf79b38bdd",
                "sha256": "c1d33aa77cb1b9377913f06fe57a7d5434697995e8664d248dc452660f8187f6"
            },
            "downloads": -1,
            "filename": "latex2pydata-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2cbf473e25b966c34632cdaf79b38bdd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12136,
            "upload_time": "2023-11-20T19:14:58",
            "upload_time_iso_8601": "2023-11-20T19:14:58.775549Z",
            "url": "https://files.pythonhosted.org/packages/6e/a5/af285da6d64c81f4e61a1be2619510ae58fca80990d9e7a1d689d9b570c6/latex2pydata-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-20 19:14:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gpoore",
    "github_project": "latex2pydata_py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "latex2pydata"
}
        
Elapsed time: 0.13937s