Skip to main content

Simple library to stream a huge XML file to a JSON file

Project description

streamxml2json

Simple library to stream a huge XML file to a JSON file

Instalation

You can install it from PyPi:

$ pip install streamxml2json

Usage

from stream_xml2json import streamxml2json

with open("input.xml", "rb") as input_file:
   stream_xml2json(input_file, "output.json", 2)

xml_input can either be an XML string or a file-like object opened in binary mode - using open(file, "rb") for example. If your xml is gzipped, for example, you might pass a GzipFile(filename) instance

json_output_filename must be a string with the relative/absolute path to where the json should be written to.

item_depth is required because of the streaming nature of the process. You must tell at which depth of the XML we want to iterate on to generate the output JSON array.

By default, we pretty-print the JSON file with 2 spaces. You can disable this pretty-printing by setting pretty to False, or customize the indentation depth by changing indent value.

We automatically display a progress bar. You can disable it by passing False to display_progress_bar. We use tqdm to display this progress bar. You can pass additional customization parameters as a dictionary to tqdm_kwargs. One interesting option is total, which will make tqdm be able to show how much longer it expects the process to take. Please check their documentation to better understand the available options.

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

streamxml2json-1.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

streamxml2json-1.0.1-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file streamxml2json-1.0.1.tar.gz.

File metadata

  • Download URL: streamxml2json-1.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for streamxml2json-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cdc973c900803622e884369a2ee47dc2433df64a4132cabc255b29a62b6cd130
MD5 bc83adce64ccfe458777d1a4866055c8
BLAKE2b-256 7494f86b344eee3f5bacd016e559a27441da3a7c9e62cfb0b7493550079f5c9e

See more details on using hashes here.

File details

Details for the file streamxml2json-1.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: streamxml2json-1.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for streamxml2json-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 72ec20852bdc3e0c2e0c20d38de1531b2db8d83f1f56b85444f5f8409a0ef47e
MD5 d08377ffc4b303d0be13110abdeaf0c6
BLAKE2b-256 dd8c307c256a5659abead39846b5f66102448d7386c642aadfaec0d568c00b55

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