As this is the absolute first thread here, I'll include some starter-content from the /samples directory of the repository.
From convenience.py, this is how you might work with Open Metadata if you weren't too interested in the internals, size of your output or performance.
"""
This module provides examples of Open Metadata convenience methods
Convenience methods are provided as a means of reading and writing
metadata where requirements in functionality and performance are low;
such as in debugging or one-off reading/writing.
"""
import os
import openmetadata as om
# Starting-point
path = os.path.expanduser(r'~\om_temp')
if not os.path.exists(path):
os.mkdir(path)
om.write(path, True, 'status')
om.write(path, 'There once was a boy', 'story')
om.write(path, 27, 'age')
data = {
'firstname': 'Marcus',
'lastname': 'Ottosson',
'email': 'konstr...@gmail.com'
}
for key, value in data.iteritems():
om.write(path, value, key)
# Write deeply nested data
om.write(path, True, 'root', 'group', 'amazing')
# Successfully wrote: c:\users\marcus\om2\.meta\status.bool
# Successfully wrote: c:\users\marcus\om2\.meta\story.string
# Successfully wrote: c:\users\marcus\om2\.meta\age.int
# Successfully wrote: c:\users\marcus\om2\.meta\lastname.string
# Successfully wrote: c:\users\marcus\om2\.meta\email.string
# Successfully wrote: c:\users\marcus\om2\.meta\firstname.string
# Successfully wrote: c:\users\marcus\om2\.meta\root\group\amazing.bool
From basic.py, provides an overview of how you may work with Open Metadata where you'd prefer greater control over the output, size and performance.
"""
This module provides basic examples for working with Open Metadata
"""
import os
import openmetadata as om
# Starting-point
path = os.path.expanduser(r'~\om_temp')
if not os.path.exists(path):
os.mkdir(path)
location = om.Location(path)
# Add a regular string
ostring = om.Dataset('simple_data.string', parent=location)
ostring.data = 'my simple string'
# Add a list
olist = om.Group('mylist.list', parent=location)
# Containing three datasets..
l1 = om.Dataset(path='item1.string', data='a string value', parent=olist)
l2 = om.Dataset(path='item2.bool', data=True, parent=olist)
l3 = om.Dataset(path='item3.int', data=5, parent=olist)
# ..and a dictionary..
odict = om.Group(path='mydict.dict', parent=olist)
# ..with two keys
key1 = om.Dataset('key1.string', data='value', parent=odict)
# One of which, we neglect to specify a data-type.
# The data-type will be determined via the Python data-type <str>
key2 = om.Dataset('key2', data='value', parent=odict)
# Finally, write it to disk.
om.dump(location)
# ----------- Read it back in
# path = r'c:\users\marcus\om2'
print om.read(path)
# --> [List('mylist.list'), String('simple_data.string')]
print om.read(path, 'mylist')
# --> [Bool('item2.bool'), Int('item3.int'), ...]
print om.read(path, 'mylist', 'item2')
# # --> True
# assert om.read == om.listdir
for item in om.listdir(path):
print item.path
# # --> c:\users\marcus\om2\.meta\mylist.list
# --> c:\users\marcus\om2\.meta\simple_data.string