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.2.0.tar.gz (32.8 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.2.0-cp38-abi3-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_xml-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

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

polars_xml-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_xml-0.2.0-cp38-abi3-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_xml-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_xml-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3154b61f352ae98a10a5b419acf7cdc44e3a8df5545fda9b0ffb6669625b4a01
MD5 b28f353367a0d591e59c4358f2275112
BLAKE2b-256 c797e4704a71db710c14f5f116435889f6c4ce45909eee64cbc153b0a59451f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_xml-0.2.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cc5cd8c079e1559256aa5baf10ece3cd8e13121d6e9c5f4ae2f2d4febfbbb340
MD5 ea687151af3165d247c31926e2528afa
BLAKE2b-256 89518278c7fdc41266abc402db85907dae83dc9ce8c0ae6b4325eb4dcf3158eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_xml-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b72adf99311dd9e32bbaa5d324fa873aabc5c12344c9ea806f44348ac02cb4bb
MD5 65c0ab24b8f2b204b6e1f71d3c556e0e
BLAKE2b-256 095e8b0ba837a2c08f866354003fcc86d1747b3fae1dc1d696aaba9c8cef3172

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_xml-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 aa4e3e5e74b3ddfb8151df9f3e503891904622b82192e3f0628c640fd21d361f
MD5 68215dd1ebe622da3e5f47ec03111041
BLAKE2b-256 50dad2de424ca320bae1070a33adc8302ed077258079f605e7239ccf393890fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_xml-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 801ae42ebb4af1b6b4a102a46f02a693c3313a2e8303bc4fdd054534db470103
MD5 6717ba2a1ca511e32ab41679b35afa0f
BLAKE2b-256 318b06cf1dac603eb3f2a509f01b1a9e83809e393a2a2a66461e73fd7ffd6800

See more details on using hashes here.

File details

Details for the file polars_xml-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_xml-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f4db23399dc4853478193a1c4a3eb584cf078db1d5161eadb8f12fc2f248f806
MD5 3b2635763c2fe8dd8711adea5ed54c50
BLAKE2b-256 1325d3ca663f2f45f8695389bdfef1c3ecb96a928188e059a57b2f86c292f02a

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