pyvgx Vertex Access Methods Description

pyvgx.Vertex.SetProperty()

Set or update a named property in the vertex.

pyvgx.Vertex.IncProperty()

Increment a property value

pyvgx.Vertex.HasProperty()

Check whether the vertex contains the named property, with optional value condition.

pyvgx.Vertex.GetProperty()

Return a vertex property.

pyvgx.Vertex.RemoveProperty()

Remove a property

pyvgx.Vertex.SetProperties()

Set many properties

pyvgx.Vertex.HasProperties()

Check whether the vertex has any properties.

pyvgx.Vertex.NumProperties()

Return the number of properties

pyvgx.Vertex.GetProperties()

Return all vertex properties as a dictionary of name → value mappings.

pyvgx.Vertex.RemoveProperties()

Remove all properties

pyvgx.Vertex.items()

Return name/value pairs

pyvgx.Vertex.keys()

Return property names

pyvgx.Vertex.values()

Return property values

1. pyvgx.Vertex.SetProperty()

Set or update a named property in the vertex.

1.1. Syntax

pyvgx.Vertex.SetProperty( name [, value[, virtual]] )

1.2. Parameters

name

The property name must be a string.

value

The property value may be a number, string, list of numeric values, dict of {int:float} items, function, or any other Python object supporting the Pickle protocol.

virtual

When True store the property value on disk instead of memory. Default is False.

1.3. Remarks

Supported value types and ranges are summarized below. Note that the primitive numeric types are limited to a 56-bit internal representation.

Table 1. Vertex Property Types
Python Type Inserted Stored in Vertex Python Type Retrieved Comment

None

None

None

A property value can be explicitly set to None or automatically set to None when no property value is specified.

bool

56-bit signed integer

int

Bool objects are interpreted as integer type, i.e. False becomes 0, True becomes 1.

int

56-bit signed integer

int

A Python integer object in the range is [-255, 255-1]

float

56-bit floating point

float

Truncation of the mantissa will lead to slight loss of precision, e.g. 3.14 → 3.1399999999999864

str

Byte array representing string data

str

Strings must be UTF-8 encoded. The upper limit for string length is not defined, but is at least 65464 octets. Longer strings are compressed internally. As long as the size of compressed data does not exceed 65465 bytes the string can be stored. Non-compressed strings are readable by evaluator expressions.

bytearray

Byte array representing raw unsigned bytes

bytearray

A list of 8-bit unsigned integers stored as a native array, which can be accessed by evaluator expressions. The maximum array length is 65464 bytes.

bytes

String of raw bytes

bytes

A list of 8-bit unsigned integers stored as a native array, which can be accessed by evaluator expressions. The maximum array length is 65464 bytes.

list
(all int, or all float)

Byte array representing multiple 64-bit integers or double precision floats

list

A list of only integers or only floats stored as a native array, which can be accessed by evaluator expressions. The maximum array length is 8183 items.

NOTE: If types are mixed (integers and floats), or if any other type appears in the list the property value will be stored as <any_other_object> described below without warning!

dict
(integer keys, float values)

Byte array representing a mapping of 32-bit integer keys to single precision float values

dict

A mapping of 32-bit signed integer keys to 32-bit single precision floating point values stored as a native hash table, which can be accessed by evaluator expressions. The maximum map size is 2703 items.

function

Serialized Python byte code, optionally compressed if large

function

Arbitrary code, executable by the Python interpreter.

<any_other_object>

Serialized Python object, optionally compressed if large

object

Any other Python object will be stored as the string produced by the objects repr() method. The size limit of the string representation is 65464 bytes (after internal compression when applicable.)

Use a serialization protocol such as JSON or Python’s own Pickle module to store complex objects.
Data types with special restrictions (such as numeric lists or integer-to-float maps) will only be stored as expected when those restrictions are met. In the case of numeric lists, non-conforming values are silently stored as serialized Python objects rather than native arrays. Dictionary properties require integer keys and numeric values, and will raise an exception if other types are used.

1.4. Example

from pyvgx import *
import cPickle
import pprint
g = Graph( "graph" )
A = g.NewVertex( "A" )
#
# Set some properties
#
A.SetProperty( "flagX" )            # None
A.SetProperty( "beware", None )     # None
A.SetProperty( "boolA", True )      # 1
A.SetProperty( "boolB", False )     # 0
A.SetProperty( "integer", -123 )    # -123
A.SetProperty( "big", 2**50 )       # 1125899906842624
A.SetProperty( "pi", 3.14 )         # 3.1399999999999864
A.SetProperty( "message", "hello" ) # "hello"
A.SetProperty( "array", [1,2,3] )   # [1, 2, 3]

# Virtual property string value stored on disk
A.SetProperty( "ondisk", "this_is_on_disk", virtual=True )

# str  : "<PyVGX_Graph: name=graph order=1 size=0>"
A.SetProperty( "the_graph", g )

# str  : "[1, 2, {'x': 'y'}]"
A.SetProperty( "objstr", [1,2,{'x':'y'}] )

# str  : "(lp1\nI1\naI2\na(dp2\nS'x'\nS'y'\nsa."
A.SetProperty( "obj", cPickle.dumps( [1,2,{'x':'y'}] ) )

#
# Get the properties
#
pprint.pprint( A.GetProperties() )
# { 'beware': None,
#   'big': 1125899906842624,
#   'boolA': 1,
#   'boolB': 0,
#   'flagX': None,
#   'integer': -123,
#   'message': 'hello',
#   'objstr': "[1, 2, {'x': 'y'}]",
#   'obj': "(lp1\nI1\naI2\na(dp2\nS'x'\nS'y'\nsa.",
#   'pi': 3.1399999999999864,
#   'array': [1, 2, 3],
#   'the_graph': '<PyVGX_Graph: name=1 order=1 size=0>' }
cPickle.loads( A.GetProperty( "obj" ) )      # [1, 2, {'x': 'y'}]

2. pyvgx.Vertex.IncProperty()

Increment property value.

3. pyvgx.Vertex.HasProperty()

Check whether the vertex contains the named property, with optional value condition.

3.1. Syntax

pyvgx.Vertex.HasProperty( name [, value_condition] )

3.2. Parameters

name

The property name to check. Must be string.

value_condition

Optional condition to apply to property value. The condition is NONE

3.3. Return Value

True: The vertex contains the named property.

False: The vertex does not contain the named property.

3.4. Example

from pyvgx import *
g = Graph( "graph" )
A = g.NewVertex( "A" )
A.HasProperty( "color" )          # -> False
A.SetProperty( "color", "red" )   #
A.HasProperty( "color" )          # -> True

4. pyvgx.Vertex.GetProperty()

Return a vertex property.

4.1. Syntax

pyvgx.Vertex.GetProperty( name, default=None )

4.2. Parameters

name

The named property whose value is to be returned.

default

Default value to return if the vertex does not contain the named property.

4.3. Return Value

This method returns the value of the named vertex property, or a default value if the named property does not exist in the vertex.

4.4. Remarks

Property values are stored as integer, floating point, or string type. Python objects other than these will be cast to a string representation.

Note that integers and floating point values are restricted to a 56-bit internal representation. See pyvgx.Vertex.SetProperty() for details.

4.5. Example

from pyvgx import *
g = Graph( "graph" )
A = g.NewVertex( "A" )
A.GetProperty( "color" )            # -> None
A.SetProperty( "color", "red" )
A.GetProperty( "color" )            # -> "red"
A.GetProperty( "size", 100 )        # -> 100
A.GetProperty( "brand", "generic" ) # -> "generic"

5. pyvgx.Vertex.RemoveProperty()

Remove a property.

6. pyvgx.Vertex.SetProperties()

Set many properties from dictionary.

7. pyvgx.Vertex.HasProperties()

Check whether the vertex has any properties.

7.1. Syntax

pyvgx.Vertex.HasProperties()

7.2. Return Value

True: The vertex contains at least one named property.

False: The vertex does not contain any named properties.

7.3. Example

from pyvgx import *
g = Graph( "graph" )
A = g.NewVertex( "A" )
A.HasProperties()                  # -> False
A.SetProperty( "color", "red" )    #
A.HasProperties()                  # -> True

8. pyvgx.Vertex.NumProperties()

Return the number of properties.

9. pyvgx.Vertex.GetProperties()

Return all vertex properties as a dictionary of name → value mappings.

9.1. Syntax

pyvgx.Vertex.GetProperties()

9.2. Return Value

A Python dictionary is returned.

9.3. Example

from pyvgx import *
g = Graph( "graph" )
A = g.NewVertex( "A" )
A.GetProperties()                  # -> {}
A.SetProperty( "color", "red" )    #
A.SetProperty( "size", 5 )         #
A.GetProperties()                  # -> {'color': 'red', 'size': 5}

10. pyvgx.Vertex.RemoveProperties()

Remove all properties.

11. pyvgx.Vertex.items()

Return name/value pairs.

12. pyvgx.Vertex.keys()

Return property names.

13. pyvgx.Vertex.values()

Return property values.


PYVGX