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.get_detected_format())
print(parser.parse())
print(parser.validate(json_schema))

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

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

parser = UniversalParser.UniversalParser(yaml_data)
print("Detected format: ", parser.get_detected_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.1.tar.gz (5.0 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.1-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.1.tar.gz.

File metadata

File hashes

Hashes for universal_parser_it_stud_io-1.0.1.tar.gz
Algorithm Hash digest
SHA256 04b601b0026430528d25ae68645733f30b48ce123c08d4035c44aa71b274675d
MD5 69f827e10053556adbd351aa0420bfd4
BLAKE2b-256 28f3cb4041d4e4ae70f63a2f0b2cefe02882187402560f716038fbd4de17964a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for universal_parser_it_stud_io-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32e97d76e9c297b04fe459ae144d0b4555d8065f5316274c0bd13594e88079d8
MD5 37ef42011667d172f26ef503697e2fcf
BLAKE2b-256 4a1632283b110f51cc12d24aec3b12cf30fbebf1872c76feb5ff9ebafc9bc342

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