lightweight, simple, and fast declarative XML and JSON data extraction
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file yankee-0.1.45.tar.gz
.
File metadata
- Download URL: yankee-0.1.45.tar.gz
- Upload date:
- Size: 89.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2c5bb24d8eb3a39f753075f5505dd766838dfb1d413e0a45f7c7837d827bf9e |
|
MD5 | 4ed09661e85f7ff0083d74c398c956a3 |
|
BLAKE2b-256 | 270faaedf7c8f1b7a022878a4d81f2a939fe8773a0ad5f8a8eccb6201640e522 |
File details
Details for the file yankee-0.1.45-py3-none-any.whl
.
File metadata
- Download URL: yankee-0.1.45-py3-none-any.whl
- Upload date:
- Size: 103.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f37e28a49bcec090bff4a00fdd2d664b18adfc2a77651ada6ef2c30bf362ba90 |
|
MD5 | 07a0322b42220ab0d8f35cbbdff86d83 |
|
BLAKE2b-256 | 8a3a99a7d763031204af5ab77a18f537ec2fffd6847ca234a43d8d15de32feda |