Skip to main content

lightweight, simple, and fast declarative XML and JSON data extraction

Project description

yankee_logo Documentation

PyPI PyPI - Python Versions PyPI - Downloads

Summary

Simple declarative data extraction and loading in Python, featuring:

  • 🍰 Ease of use: Data extraction is performed in a simple, declarative types.
  • XML / HTML / JSON Extraction: Extraction can be performed across a wide array of structured data
  • 🐼 Pandas Integration: Results are easily castable to Pandas Dataframes and Series.
  • 😀 Custom Output Classes: Results can be automatically loaded into autogenerated dataclasses, or custom model types.
  • 🚀 Performance: XML loading is supported by the excellent and fast lxml library, JSON is supported by UltraJSON for fast parsing, and jsonpath_ng for flexible data extraction.

Quick Start

To extract data from XML, use this import statement, and see the example below:

from yankee.xml.schema import Schema, fields as f, CSSSelector

To extract data from JSON, use this import statement, and see the example below:

from yankee.xml.schema import Schema, fields as f, JSONPath

To extract data from HTML, use this import statement:

from yankee.html.schema import Schema, fields as f, CSSSelector

To extract data from Python objects (either objects or dictionaries), use this import statement:

from yankee.base.schema import Schema, fields as f

Documentation

Complete documentation is available on Read The Docs

Examples

Extract data from XML

Data extraction from XML. By default, data keys are XPath expressions, but can also be CSS selectors.

Take this:

    <xmlObject>
        <name>Johnny Appleseed</name>
        <birthdate>2000-01-01</birthdate>
        <something>
            <many>
                <levels>
                    <deep>123</deep>
                </levels>
            </many>
        </something>
    </xmlObject>

Do this:

from yankee.xml.schema import Schema, fields as f, CSSSelector

class XmlExample(Schema):
    name = f.String("./name")
    birthday = f.Date(CSSSelector("birthdate"))
    deep_data = f.Int("./something/many/levels/deep")

XmlExample().load(xml_doc)

Get this:

{
    "name": "Johnny Appleseed",
    "birthday": datetime.date(2000, 1, 1),
    "deep_data": 123
}

Extract data from JSON

Data extraction from JSON. By default, data keys are implied from the field names, but can also be JSONPath expressions

Take this:

{
        "name": "Johnny Appleseed",
        "birthdate": "2000-01-01",
        "something": [
            {"many": {
                "levels": {
                    "deep": 123
                }
            }}
        ]
    }

Do this:

from yankee.json.schema import Schema, fields as f

class JsonExample(Schema):
    name = f.String()
    birthday = f.Date("birthdate")
    deep_data = f.Int("something.0.many.levels.deep")

Get this:

{
    "name": "Johnny Appleseed",
    "birthday": datetime.date(2000, 1, 1),
    "deep_data": 123
}

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

yankee-0.1.42.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

yankee-0.1.42-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file yankee-0.1.42.tar.gz.

File metadata

  • Download URL: yankee-0.1.42.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for yankee-0.1.42.tar.gz
Algorithm Hash digest
SHA256 1889b52a8db5e6491c3defb4aac2c870a38ba08582bb3563ec7d74fc2632f3a5
MD5 3251e359ec4e8d3088bef3f29b7ff7bf
BLAKE2b-256 0d627314ff6ce11d41ffd6619199a6693c67f99019cac8e5cc4a29f7c2a13d84

See more details on using hashes here.

File details

Details for the file yankee-0.1.42-py3-none-any.whl.

File metadata

  • Download URL: yankee-0.1.42-py3-none-any.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for yankee-0.1.42-py3-none-any.whl
Algorithm Hash digest
SHA256 971957e6eef187427c04fc251a11cf1dca18e84daacd7c825a2e259116fe1406
MD5 3a0fc2c3fab31f234fd8fab4883821eb
BLAKE2b-256 ecf59d50bba5b284febdff80b26ebe505399d28222a63b48ecec8826aec8f233

See more details on using hashes here.

Supported by

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