Datatypes

edgedb-python automatically converts EdgeDB types to the corresponding Python types and vice versa.

The table below shows the correspondence between EdgeDB and Python types.

EdgeDB Type

Python Type

Set

edgedb.Set

array<anytype>

edgedb.Array

anytuple

edgedb.Tuple or edgedb.NamedTuple

anyenum

str

Object

edgedb.Object

bool

bool

bytes

bytes

str

str

cal::local_date

datetime.date

cal::local_time

offset-naive datetime.time

cal::local_datetime

offset-naive datetime.datetime

datetime

offset-aware datetime.datetime

duration

datetime.timedelta

float32, float64

float

int16, int32, int64, bigint

int

decimal

Decimal

json

str

uuid

uuid.UUID

Inexact single-precision float values may have a different representation when decoded into a Python float. This is inherent to the implementation of limited-precision floating point types. If you need the decimal representation to match, cast the expression to float64 or decimal in your query.

class
Set

A representation of an immutable set of values returned by a query.

The BlockingIOConnection.query() and AsyncIOConnection.query() methods return an instance of this type. Nested sets in the result are also returned as Set objects.

interface
len(s)

Return the number of fields in set s.

interface
iter(s)

Return an iterator over the values of the set s.

class
Object

An immutable representation of an object instance returned from a query.

The value of an object property or a link can be accessed through a corresponding attribute:

Copy
>>> 
import edgedb
Copy
>>> 
conn = edgedb.connect()
Copy
>>> 
... 
... 
... 
r = conn.query_one('''
    SELECT schema::ObjectType {name}
    FILTER .name = 'std::Object'
    LIMIT 1''')
Copy
>>> 
r
Object{name := 'std::Object'}
Copy
>>> 
r.name
'std::Object'
interface
obj[linkname]

Return a edgedb.Link or a edgedb.LinkSet instance representing the instance(s) of link linkname associated with obj.

Example:

Copy
>>> 
import edgedb
Copy
>>> 
conn = edgedb.connect()
Copy
>>> 
... 
... 
... 
... 
r = conn.query_one('''
    SELECT schema::Property {name, annotations: {name, @value}}
    FILTER .name = 'listen_port'
           AND .source.name = 'cfg::Config'
    LIMIT 1''')
Copy
>>> 
r
Object {
    name: 'listen_port',
    annotations: {
        Object {
            name: 'cfg::system',
            @value: 'true'
        }
    }
}
Copy
>>> 
r['annotations']
LinkSet(name='annotations')
Copy
>>> 
l = list(r['annotations])[0]
Copy
>>> 
l.value
'true'
class
Tuple

An immutable value representing an EdgeDB tuple value.

Instances of edgedb.Tuple generally behave exactly like standard Python tuples:

Copy
>>> 
import edgedb
Copy
>>> 
conn = edgedb.connect()
Copy
>>> 
r = conn.query_one('''SELECT (1, 'a', [3])''')
Copy
>>> 
r
(1, 'a', [3])
Copy
>>> 
len(r)
3
Copy
>>> 
r[1]
'a'
Copy
>>> 
r == (1, 'a', [3])
True
class
NamedTuple

An immutable value representing an EdgeDB named tuple value.

Instances of edgedb.NamedTuple generally behave similarly to namedtuple:

Copy
>>> 
import edgedb
Copy
>>> 
conn = edgedb.connect()
Copy
>>> 
r = conn.query_one('''SELECT (a := 1, b := 'a', c := [3])''')
Copy
>>> 
r
(a := 1, b := 'a', c := [3])
Copy
>>> 
r.b
'a'
Copy
>>> 
r[0]
1
Copy
>>> 
r == (1, 'a', [3])
True
class
Array

An immutable value representing an EdgeDB array value.

Copy
>>> 
import edgedb
Copy
>>> 
conn = edgedb.connect()
Copy
>>> 
r = conn.query_one('''SELECT [1, 2, 3]''')
Copy
>>> 
r
[1, 2, 3]
Copy
>>> 
len(r)
3
Copy
>>> 
r[1]
2
Copy
>>> 
r == [1, 2, 3]
True
Light
Dark
System