Skip to content
/ dipl Public

Quick reader and parser of DIP language for Python

License

Notifications You must be signed in to change notification settings

vrtulka23/dipl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Installation

Python module dipl can be installed using pip from the PyPi repository:

pip3 install dipl

Loading 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.QUANTITY)
{
  'width': Quantity(23.34, 'cm'),
  'age': Quantity(23, 'yr'),
}

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'),
}

Dumping 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]

About

Quick reader and parser of DIP language for Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages