xlineparse


Namexlineparse JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryParse variable length delimited lines
upload_time2024-05-10 12:45:37
maintainerNone
docs_urlNone
authorOliver Russell <ojhrussell@gmail.com>
requires_python>=3.10
licenseNone
keywords diff
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # xlineparse

Python library to parse variable length delimited lines.

# Usage

```shell
pip install xlineparse
```

```python
import datetime as dt
from decimal import Decimal
from typing import Annotated, Literal

import xlineparse as xlp

FooLine = tuple[
    Literal["foo"],
    int,
    Decimal,
    Decimal | None,
    Annotated[bool, xlp.BoolField(true_value="Y", false_value="F")],
    Annotated[dt.date, xlp.DateField(format="%Y-%m-%d")],
    Annotated[dt.time, xlp.TimeField(format="%H%M%s")],
]
BarLine = tuple[
    Literal["bar"],
    int,
]
schema = xlp.Schema.from_type(
    delimiter="|",
    quote_str=None,
    trailing_delimiter=False,
    lines=FooLine | BarLine,
)

schema.parse_line("foo|1|3.14||Y|2012-01-02|123200")

#  Will return:

(
    "foo",
    1,
    Decimal("3.14"),
    None,
    True,
    dt.date(2012, 1, 2),
    dt.time(12, 32, 0),
)
```

Or directly construct `Field`s:

```python
schema = xlp.Schema(
    delimiter="|",
    quote_str=None,
    trailing_delimiter=False,
    lines=[
        xlp.Line(
            name="a",
            fields=[
                xlp.DecimalField(
                    required=True,
                    round_decimal_places=None,
                    min_value=Decimal("2.0"),
                    max_value=None,
                )
            ],
        )
    ],
)
assert schema.parse_line("a|2.0")

#  Will return:

("a", Decimal("2.0"))
```

# TODO:

- Maybe the big decimals are just floats?
- Allow delimiters to be escaped.
- Can we make enums quicker by moving to Rust?

# Install/Develop

```shell
uv pip install -e '.[dev]'
maturin develop
```

# Make release

- Add pypi token and user = `__token__` to settings (do this once).
- Upversion `pyproject.toml`.

```shell
git tag -a v0.0.x head -m v0.0.x
git push origin v0.0.x
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "xlineparse",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Oliver Russell <ojhrussell@gmail.com>",
    "keywords": "diff",
    "author": "Oliver Russell <ojhrussell@gmail.com>",
    "author_email": "Oliver Russell <ojhrussell@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "# xlineparse\n\nPython library to parse variable length delimited lines.\n\n# Usage\n\n```shell\npip install xlineparse\n```\n\n```python\nimport datetime as dt\nfrom decimal import Decimal\nfrom typing import Annotated, Literal\n\nimport xlineparse as xlp\n\nFooLine = tuple[\n    Literal[\"foo\"],\n    int,\n    Decimal,\n    Decimal | None,\n    Annotated[bool, xlp.BoolField(true_value=\"Y\", false_value=\"F\")],\n    Annotated[dt.date, xlp.DateField(format=\"%Y-%m-%d\")],\n    Annotated[dt.time, xlp.TimeField(format=\"%H%M%s\")],\n]\nBarLine = tuple[\n    Literal[\"bar\"],\n    int,\n]\nschema = xlp.Schema.from_type(\n    delimiter=\"|\",\n    quote_str=None,\n    trailing_delimiter=False,\n    lines=FooLine | BarLine,\n)\n\nschema.parse_line(\"foo|1|3.14||Y|2012-01-02|123200\")\n\n#  Will return:\n\n(\n    \"foo\",\n    1,\n    Decimal(\"3.14\"),\n    None,\n    True,\n    dt.date(2012, 1, 2),\n    dt.time(12, 32, 0),\n)\n```\n\nOr directly construct `Field`s:\n\n```python\nschema = xlp.Schema(\n    delimiter=\"|\",\n    quote_str=None,\n    trailing_delimiter=False,\n    lines=[\n        xlp.Line(\n            name=\"a\",\n            fields=[\n                xlp.DecimalField(\n                    required=True,\n                    round_decimal_places=None,\n                    min_value=Decimal(\"2.0\"),\n                    max_value=None,\n                )\n            ],\n        )\n    ],\n)\nassert schema.parse_line(\"a|2.0\")\n\n#  Will return:\n\n(\"a\", Decimal(\"2.0\"))\n```\n\n# TODO:\n\n- Maybe the big decimals are just floats?\n- Allow delimiters to be escaped.\n- Can we make enums quicker by moving to Rust?\n\n# Install/Develop\n\n```shell\nuv pip install -e '.[dev]'\nmaturin develop\n```\n\n# Make release\n\n- Add pypi token and user = `__token__` to settings (do this once).\n- Upversion `pyproject.toml`.\n\n```shell\ngit tag -a v0.0.x head -m v0.0.x\ngit push origin v0.0.x\n```\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Parse variable length delimited lines",
    "version": "0.0.6",
    "project_urls": {
        "documentation": "https://github.com/leontrolski/xlineparse",
        "homepage": "https://github.com/leontrolski/xlineparse",
        "repository": "https://github.com/leontrolski/xlineparse.git"
    },
    "split_keywords": [
        "diff"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a0c89517897819729ccb581e68a6ac0b87538f082d8ab0234f2b10717e2577c",
                "md5": "6424bfe22d8e15fef418b9878bab5fbd",
                "sha256": "61ccbe833f1ddf3a430c3235f1b8933c9c9b6b5854b2585e5edcd58628cbb51b"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp310-cp310-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "6424bfe22d8e15fef418b9878bab5fbd",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 488698,
            "upload_time": "2024-05-10T12:45:37",
            "upload_time_iso_8601": "2024-05-10T12:45:37.212880Z",
            "url": "https://files.pythonhosted.org/packages/9a/0c/89517897819729ccb581e68a6ac0b87538f082d8ab0234f2b10717e2577c/xlineparse-0.0.6-cp310-cp310-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "433bb67b62d8d1c5de243b7cd8209177a3f8302ec763ca4792f38414ddbf961e",
                "md5": "f174e9313382bd05d2af3d6834a5fd2e",
                "sha256": "37bbc3698d16b1f7200aefe88c9096cc5d245f8994d2e17c98153b1e3ffbd957"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp310-cp310-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "f174e9313382bd05d2af3d6834a5fd2e",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 489507,
            "upload_time": "2024-05-10T12:45:36",
            "upload_time_iso_8601": "2024-05-10T12:45:36.535460Z",
            "url": "https://files.pythonhosted.org/packages/43/3b/b67b62d8d1c5de243b7cd8209177a3f8302ec763ca4792f38414ddbf961e/xlineparse-0.0.6-cp310-cp310-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51378ac919f629f40e046c0f35d7be358f81c2a14c6391f1be81b5f365ad006a",
                "md5": "b1fb36dc0241929769c145b32a1d5f04",
                "sha256": "35ef78204ce80616f2f87a42c27cbe8a72b85d3b059eedd5a64f746588ce41cf"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b1fb36dc0241929769c145b32a1d5f04",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 658639,
            "upload_time": "2024-05-10T12:45:19",
            "upload_time_iso_8601": "2024-05-10T12:45:19.452067Z",
            "url": "https://files.pythonhosted.org/packages/51/37/8ac919f629f40e046c0f35d7be358f81c2a14c6391f1be81b5f365ad006a/xlineparse-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8bab5d788a93687e8cd956634e55657dfa521ae13693cbb8346ebf9b04d21ca9",
                "md5": "2e88fbfd7393d85b85053ff52de17230",
                "sha256": "08a8892be1d66806aeab50f559cbecc78ed1a788ce38976923fb7be87a965e4a"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "2e88fbfd7393d85b85053ff52de17230",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 652478,
            "upload_time": "2024-05-10T12:45:20",
            "upload_time_iso_8601": "2024-05-10T12:45:20.864945Z",
            "url": "https://files.pythonhosted.org/packages/8b/ab/5d788a93687e8cd956634e55657dfa521ae13693cbb8346ebf9b04d21ca9/xlineparse-0.0.6-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44160ebaf1d17fce351616a5bdfafa70c41d110f3115072d0ec014471390a4b1",
                "md5": "977125911e4b8033ea72eec9a5155cea",
                "sha256": "873fec527eb9216d36f79564294339d31d93588ac853da1e4b77e20f09b63ec8"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp311-cp311-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "977125911e4b8033ea72eec9a5155cea",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.10",
            "size": 488743,
            "upload_time": "2024-05-10T12:44:52",
            "upload_time_iso_8601": "2024-05-10T12:44:52.940380Z",
            "url": "https://files.pythonhosted.org/packages/44/16/0ebaf1d17fce351616a5bdfafa70c41d110f3115072d0ec014471390a4b1/xlineparse-0.0.6-cp311-cp311-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92f20a8d3adc5437ffb23403bbefea3e30c7470bfc55a6c036c0131e3e80d760",
                "md5": "46a41800fb96842639dfcb26737815a7",
                "sha256": "4e3086ccf2b41da8594b56f0ad00b5a636090e3894340a1b0f603008ae1d652f"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp311-cp311-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "46a41800fb96842639dfcb26737815a7",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.10",
            "size": 489418,
            "upload_time": "2024-05-10T12:45:03",
            "upload_time_iso_8601": "2024-05-10T12:45:03.819203Z",
            "url": "https://files.pythonhosted.org/packages/92/f2/0a8d3adc5437ffb23403bbefea3e30c7470bfc55a6c036c0131e3e80d760/xlineparse-0.0.6-cp311-cp311-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37167686cd5130b105f56c9ddc0d3641b43aa8c31c9352cde60639f7d5877ae4",
                "md5": "b57978716c28d7417879e875db801daa",
                "sha256": "90118783c0bf77c80d7361f51f3626ceb5931637406e334a48e79dfe1c907249"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b57978716c28d7417879e875db801daa",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.10",
            "size": 658687,
            "upload_time": "2024-05-10T12:45:21",
            "upload_time_iso_8601": "2024-05-10T12:45:21.705907Z",
            "url": "https://files.pythonhosted.org/packages/37/16/7686cd5130b105f56c9ddc0d3641b43aa8c31c9352cde60639f7d5877ae4/xlineparse-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75c4eb5cbcc8a75b9d2b68cdc4f92f304443af26fd7080169d193127be38aa9d",
                "md5": "af5e5d63146cd812787a3fc9bbbe1a69",
                "sha256": "bee2ae28cad2441543a0f718f492f7c4a757c5b638168f53e1abd952d12425a6"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "af5e5d63146cd812787a3fc9bbbe1a69",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.10",
            "size": 652694,
            "upload_time": "2024-05-10T12:45:23",
            "upload_time_iso_8601": "2024-05-10T12:45:23.308120Z",
            "url": "https://files.pythonhosted.org/packages/75/c4/eb5cbcc8a75b9d2b68cdc4f92f304443af26fd7080169d193127be38aa9d/xlineparse-0.0.6-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "35339aca6df117a06c30811b544ca3899c8553dce540d9f15ebbe3dc93a13bc1",
                "md5": "740482af3145fa833ef196a3d34b0b78",
                "sha256": "c7f4f8a5f9638003e9a5f56f0d87d76482dc1a5ae19967031a331aa6b03ad488"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp312-cp312-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "740482af3145fa833ef196a3d34b0b78",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.10",
            "size": 488179,
            "upload_time": "2024-05-10T12:44:48",
            "upload_time_iso_8601": "2024-05-10T12:44:48.923283Z",
            "url": "https://files.pythonhosted.org/packages/35/33/9aca6df117a06c30811b544ca3899c8553dce540d9f15ebbe3dc93a13bc1/xlineparse-0.0.6-cp312-cp312-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37fbd8285d17768f654e459d14438be19e4d2072cb9496b2d2e25ee655e33a0a",
                "md5": "6aa6d6863961315f24eff6f4af99f779",
                "sha256": "52d9b53fec7b3f69d3da785f959651d1d0c4033db34ed8f032c7e7185041929f"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp312-cp312-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "6aa6d6863961315f24eff6f4af99f779",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.10",
            "size": 488876,
            "upload_time": "2024-05-10T12:45:47",
            "upload_time_iso_8601": "2024-05-10T12:45:47.857062Z",
            "url": "https://files.pythonhosted.org/packages/37/fb/d8285d17768f654e459d14438be19e4d2072cb9496b2d2e25ee655e33a0a/xlineparse-0.0.6-cp312-cp312-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "720ccc74696aee116b06c226e9a421de97ee9ba362050ad2b9fa1eaac729d430",
                "md5": "9d27d4b879ea1f5777b49951a33fe56c",
                "sha256": "6dff9dae62f339802fa3aa698f08f2bcbcfc1adad51f7eb351ebeff3d017dc26"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "9d27d4b879ea1f5777b49951a33fe56c",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.10",
            "size": 657759,
            "upload_time": "2024-05-10T12:45:14",
            "upload_time_iso_8601": "2024-05-10T12:45:14.431561Z",
            "url": "https://files.pythonhosted.org/packages/72/0c/cc74696aee116b06c226e9a421de97ee9ba362050ad2b9fa1eaac729d430/xlineparse-0.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2fd5d91e29589245533a9cd4719636bd54c6473d80535ae221d3d6214b27b18",
                "md5": "665897570ebd381dea2d978e22d48f74",
                "sha256": "5369069181b5de5f313833fbd661f9754e123c3b0e6901572de9c62402fb8d67"
            },
            "downloads": -1,
            "filename": "xlineparse-0.0.6-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "665897570ebd381dea2d978e22d48f74",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.10",
            "size": 652065,
            "upload_time": "2024-05-10T12:45:16",
            "upload_time_iso_8601": "2024-05-10T12:45:16.283964Z",
            "url": "https://files.pythonhosted.org/packages/a2/fd/5d91e29589245533a9cd4719636bd54c6473d80535ae221d3d6214b27b18/xlineparse-0.0.6-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-10 12:45:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "leontrolski",
    "github_project": "xlineparse",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "xlineparse"
}
        
Elapsed time: 3.51566s