Quick Start

Create a Simplest Tree

You can create a simplest tree like this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from treevalue import FastTreeValue

t = FastTreeValue({
    'a': 1,
    'b': 2.3,
    'x': {
        'c': 'str',
        'd': [1, 2, None],
        'e': b'bytes',
    }
})

if __name__ == '__main__':
    print(t)

A tree value object with the following structure will be created

../../_images/simple_demo.dat.svg

The output of the code above should be

1
2
3
4
5
6
7
<FastTreeValue 0x7f36d15ff6d0>
├── 'a' --> 1
├── 'b' --> 2.3
└── 'x' --> <FastTreeValue 0x7f36d15ff940>
    ├── 'c' --> 'str'
    ├── 'd' --> [1, 2, None]
    └── 'e' --> b'bytes'

Create a Slightly Complex Tree

You can easily create a tree value object which is slightly complex, based on FastTreeValue.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from treevalue import FastTreeValue

t1 = FastTreeValue({'a': 's1', 'b': 2, 'x': {'c': 3, 'd': [1, 2]}})
t2 = FastTreeValue({'a': 'str11', 'b': 2, 'x': {'c': 33, 'd': t1.x.d}})
t3 = FastTreeValue({'t1': t1, 't2': t2, 'sum': t1 + t2})

if __name__ == '__main__':
    print('t1:')
    print(t1)

    print('t2:')
    print(t2)

    print('t3:')
    print(t3)

The result should be

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
t1:
<FastTreeValue 0x7fb19c7bf6d0>
├── 'a' --> 's1'
├── 'b' --> 2
└── 'x' --> <FastTreeValue 0x7fb19c7bf940>
    ├── 'c' --> 3
    └── 'd' --> [1, 2]

t2:
<FastTreeValue 0x7fb19c3aee20>
├── 'a' --> 'str11'
├── 'b' --> 2
└── 'x' --> <FastTreeValue 0x7fb19ca86370>
    ├── 'c' --> 33
    └── 'd' --> [1, 2]

t3:
<FastTreeValue 0x7fb19bb5acd0>
├── 'sum' --> <FastTreeValue 0x7fb19ca860d0>
│   ├── 'a' --> 's1str11'
│   ├── 'b' --> 4
│   └── 'x' --> <FastTreeValue 0x7fb19c3aee50>
│       ├── 'c' --> 36
│       └── 'd' --> [1, 2, 1, 2]
├── 't1' --> <FastTreeValue 0x7fb19c7bf6d0>
│   ├── 'a' --> 's1'
│   ├── 'b' --> 2
│   └── 'x' --> <FastTreeValue 0x7fb19c7bf940>
│       ├── 'c' --> 3
│       └── 'd' --> [1, 2]
└── 't2' --> <FastTreeValue 0x7fb19c3aee20>
    ├── 'a' --> 'str11'
    ├── 'b' --> 2
    └── 'x' --> <FastTreeValue 0x7fb19ca86370>
        ├── 'c' --> 33
        └── 'd' --> [1, 2]

Three simple treevalue structures are created. Then save the code above to demo.py, and then input this shell command in your terminal.

1
treevalue graph -t 'complex_demo.*' -c 'bgcolor=#ffffff00' -d list -o complex_demo.dat.svg

A graph named demo.dat.svg will be generated, like this.

../../_images/complex_demo.dat.svg

Now you are successfully started.