Skip to main content

No project description provided

Project description

polars-xml

This is a very simple Polars plugin that allows querying xml in a string column with XPath.

It has just one function, xpath, which accepts an expression and a valid xpath statement.

import polars as pl
import polars_xml as px

rows = []
for i in range(1000):
    sample_xml = f"""
    <foo>
        <bar quux="hello from quux {i}">hello from bar {i}</bar>
        <baz xyzzy="hello from xyzzy {i}">hello from baz {i}</baz>
    </foo>
    """
    rows.append(
        {
            "index": i,
            "xml_data": sample_xml,
        }
    )

df = pl.DataFrame(rows).select(
    index=pl.col("index"),
    bar=px.xpath(pl.col("xml_data"), "//foo//bar"),
    baz=px.xpath(pl.col("xml_data"), "//foo//baz"),
    quux=px.xpath(pl.col("xml_data"), "//foo//bar/@quux"),
    xyzzy=px.xpath(pl.col("xml_data"), "//foo//baz/@xyzzy"),
    missing=px.xpath(pl.col("xml_data"), "//foo//wow"),
)

print(df)
shape: (1_000, 6)
┌───────┬────────────────────────┬────────────────────────┬─────────────────────────┬──────────────────────────┬───────────┐
│ index ┆ bar                    ┆ baz                    ┆ quux                    ┆ xyzzy                    ┆ missing   │
│ ---   ┆ ---                    ┆ ---                    ┆ ---                     ┆ ---                      ┆ ---       │
│ i64   ┆ list[str]              ┆ list[str]              ┆ list[str]               ┆ list[str]                ┆ list[str] │
╞═══════╪════════════════════════╪════════════════════════╪═════════════════════════╪══════════════════════════╪═══════════╡
│ 0     ┆ ["hello from bar 0"]   ┆ ["hello from baz 0"]   ┆ ["hello from quux 0"]   ┆ ["hello from xyzzy 0"]   ┆ []        │
│ 1     ┆ ["hello from bar 1"]   ┆ ["hello from baz 1"]   ┆ ["hello from quux 1"]   ┆ ["hello from xyzzy 1"]   ┆ []        │
│ 2     ┆ ["hello from bar 2"]   ┆ ["hello from baz 2"]   ┆ ["hello from quux 2"]   ┆ ["hello from xyzzy 2"]   ┆ []        │
│ 3     ┆ ["hello from bar 3"]   ┆ ["hello from baz 3"]   ┆ ["hello from quux 3"]   ┆ ["hello from xyzzy 3"]   ┆ []        │
│ 4     ┆ ["hello from bar 4"]   ┆ ["hello from baz 4"]   ┆ ["hello from quux 4"]   ┆ ["hello from xyzzy 4"]   ┆ []        │
│ …     ┆ …                      ┆ …                      ┆ …                       ┆ …                        ┆ …         │
│ 995   ┆ ["hello from bar 995"] ┆ ["hello from baz 995"] ┆ ["hello from quux 995"] ┆ ["hello from xyzzy 995"] ┆ []        │
│ 996   ┆ ["hello from bar 996"] ┆ ["hello from baz 996"] ┆ ["hello from quux 996"] ┆ ["hello from xyzzy 996"] ┆ []        │
│ 997   ┆ ["hello from bar 997"] ┆ ["hello from baz 997"] ┆ ["hello from quux 997"] ┆ ["hello from xyzzy 997"] ┆ []        │
│ 998   ┆ ["hello from bar 998"] ┆ ["hello from baz 998"] ┆ ["hello from quux 998"] ┆ ["hello from xyzzy 998"] ┆ []        │
│ 999   ┆ ["hello from bar 999"] ┆ ["hello from baz 999"] ┆ ["hello from quux 999"] ┆ ["hello from xyzzy 999"] ┆ []        │
└───────┴────────────────────────┴────────────────────────┴─────────────────────────┴──────────────────────────┴───────────┘

Project details


Download files

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

Source Distribution

polars_xml-0.3.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

polars_xml-0.3.0-cp38-abi3-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_xml-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

polars_xml-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_xml-0.3.0-cp38-abi3-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file polars_xml-0.3.0.tar.gz.

File metadata

  • Download URL: polars_xml-0.3.0.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.10.1

File hashes

Hashes for polars_xml-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4850baef25e3ce5e652817d142922d021dd4fc5554360573e8190f969e85e531
MD5 1d3bf9864c45c57f33e24f55d0a2df27
BLAKE2b-256 3b343a6e55e7f84a312e841392f2f8c93039c375dbd1d556611b8a2084905f2b

See more details on using hashes here.

File details

Details for the file polars_xml-0.3.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_xml-0.3.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0cee37e89235bfa8516d1500cc72ef0e7fd0d249692b19a93fc53cfe1d65c3e4
MD5 7ea7f36e15f9b44b4fd0b09ec0079b4b
BLAKE2b-256 ac6a56230539f115db20fcafe1d9fb79f8fa258547f7b2b1528f00ea1da2a28b

See more details on using hashes here.

File details

Details for the file polars_xml-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_xml-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a37c2c4f85e782a1744381e348e0ee1c813057b0df0a0b479b306b5a954305ce
MD5 d66710ba77c768ee4e2c19addc80f91b
BLAKE2b-256 733eceb2342a9809f70d1aa3369a03e5a2a2e49a3484269f741ad607a0606923

See more details on using hashes here.

File details

Details for the file polars_xml-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_xml-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b4e27dcca3dc6345568d94b844a14c70825908319dc301a408b9e484cc912f59
MD5 3bb8c00219a3735f17af747cc958cb94
BLAKE2b-256 a087cb6b60086fb0f09ab991b4a418950508332339f187f826cdc1c5c483c0ce

See more details on using hashes here.

File details

Details for the file polars_xml-0.3.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_xml-0.3.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a584e9e112be0a1fd1604324b451e0e9e6cc2c945d8aad8703e76871540d0ce
MD5 ca519fbd2b2b6ac6ed4322885568a0a3
BLAKE2b-256 3c7efa4b0bf3e5add0df37cfeada022c1bd36a410f078eb0f7ab388eb4dcaa75

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page