Skip to main content

Python reader and parser module for DIP language

Project description

DIPL

This module is a quick reading/parsing tool for Dimensional Input Parameter Language (DIP) that is a part of larger scinumtools project. For more information about DIP, please visit its official documentation. More functionality can be reqested in GitHub Issues.

Reading DIP code

Loading DIP code from a string is straightforward.

>>> import dipl
>>>
>>> text = """
>>> width float = 23.34 cm
>>> age int = 23 yr
>>>   !tags ["body"]
>>> """
>>> dipl.load(text)
{
  'width': (23.34, 'cm'),
  'age': (23, 'yr')
}

It is also possible to change data output format,

>>> from dipl import Format
>>> dipl.load(text, Format.VALUE)
{
  'width': 23.34,
  'age': 23,
}

or to select only requested nodes using query, or tags:

>>> dipl.load(text, query="width")
{
  'width': (23.34, 'cm'),
}
>>> dipl.load(text, tags=["body"])
{
  'age': (23, 'yr'),
}

Parsing DIP code

Python dictionaries can be parsed into DIP code, provided that they have a proper structure. An example parsing is shown below.

>>> import dipl
>>> import numpy as np
>>> from scinumtools.units import Quatity
>>>
>>> data = {
>>>     'body': {
>>>         'width': Quantity(172.34, 'cm'),
>>>         'age': (23, 'yr'),
>>>     },
>>>     'married': True,
>>>     'name': "John",
>>>     'kids': ["Alice","Williams"],
>>>     'lucky_numbers': np.array([23, 34, 5]),
>>> }
>>> dipl.dump(data)
body
  width float = 172.34 cm
  age int = 23 yr
married bool = true
name str = "John"
kids str[2] = ["Alice","Williams"]
lucky_numbers int[3] = [23,34,5]

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

dipl-1.1.0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

dipl-1.1.0-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

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