Skip to main content

An universal parser for various file formats

Project description

universal-parser

An universal parser for various file formats.

usage

This package can be used to parse and validate data from various file formats like JSON, XML, CSV, YAML.

install univeral-parser package

pip install -r universal-parser-it-stud-io

create app.py file

json_data = '{"name": "John", "age": 30}'
json_schema = {
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer"}
    },
    "required": ["name", "age"]
}

xml_data = '<person><name>John</name><age>30</age></person>'
xml_schema = '''
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="person">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:string"/>
        <xs:element name="age" type="xs:integer"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
'''

csv_data = 'name,age\nJohn,30'
csv_schema = {
    "name": str,
    "age": int
}

yaml_data = '''
name: John
age: 30
'''
yaml_schema = {
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer"}
    },
    "required": ["name", "age"]
}

from universal_parser_it_stud_io import UniversalParser

parser = UniversalParser.UniversalParser(json_data)
print("Detected format: ", parser._data_format)
print(parser.parse())
print(parser.validate(json_schema))

parser = UniversalParser.UniversalParser(xml_data)
print("Detected format: ", parser._data_format)
print(parser.parse())
print(parser.validate(xml_schema))

parser = UniversalParser.UniversalParser(csv_data)
print("Detected format: ", parser._data_format)
print(parser.parse())
print(parser.validate(csv_schema))

parser = UniversalParser.UniversalParser(yaml_data)
print("Detected format: ", parser._data_format)
print(parser.parse())
print(parser.validate(yaml_schema))

run app.py

python app.py

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

universal_parser_it_stud_io-1.0.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

universal_parser_it_stud_io-1.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file universal_parser_it_stud_io-1.0.0.tar.gz.

File metadata

File hashes

Hashes for universal_parser_it_stud_io-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b480ee86291eb17964dd98992ede15908d0fa04b11a751667526af43fb0a0169
MD5 32b2ce81ef30fd4ec6279c36b6603922
BLAKE2b-256 53a39c957f0d1029f51303da83c429d6249c7bc03f1a5f5ca2fe1fdd8ff9ee8c

See more details on using hashes here.

File details

Details for the file universal_parser_it_stud_io-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for universal_parser_it_stud_io-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b090db2f5a97df28d60db8a34d52d010c90675362c666edbfb480132c4175f5
MD5 d693e487da01144c857ec04bc2a3e5c4
BLAKE2b-256 6536643dba6d9460192aa148c6637677ab2571e4e7bae446217785c29686b22d

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