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

cal::relative_duration

edgedb.RelativeDuration

cal::date_duration

edgedb.DateDuration

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.

Sets

class

Set

Datatypes - 图1

Datatypes - 图2

Datatypes - 图3

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

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

interface

len(s)

Datatypes - 图4

Datatypes - 图5

Datatypes - 图6

Return the number of fields in set s.

interface

iter(s)

Datatypes - 图7

Datatypes - 图8

Datatypes - 图9

Return an iterator over the values of the set s.

Objects

class

Object

Datatypes - 图10

Datatypes - 图11

Datatypes - 图12

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:

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  2. ...
  3. ...
  4. ...
  1. r = client.query_single('''
  2. SELECT schema::ObjectType {name}
  3. FILTER .name = 'std::Object'
  4. LIMIT 1''')
  1. >>>
  1. r
  1. Object{name := 'std::Object'}
  1. >>>
  1. r.name
  1. 'std::Object'

interface

obj[linkname]

Datatypes - 图13

Datatypes - 图14

Datatypes - 图15

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

Example:

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  2. ...
  3. ...
  4. ...
  5. ...
  1. r = client.query_single('''
  2. SELECT schema::Property {name, annotations: {name, @value}}
  3. FILTER .name = 'listen_port'
  4. AND .source.name = 'cfg::Config'
  5. LIMIT 1''')
  1. >>>
  1. r
  1. Object {
  2. name: 'listen_port',
  3. annotations: {
  4. Object {
  5. name: 'cfg::system',
  6. @value: 'true'
  7. }
  8. }
  9. }
  1. >>>
  1. r['annotations']
  1. LinkSet(name='annotations')
  1. >>>
  1. l = list(r['annotations])[0]
  1. >>>
  1. l.value
  1. 'true'

class

Link

Datatypes - 图16

Datatypes - 图17

Datatypes - 图18

An immutable representation of an object link.

Links are created when edgedb.Object is accessed via a [] operator. Using Link objects explicitly is useful for accessing link properties.

class

LinkSet

Datatypes - 图19

Datatypes - 图20

Datatypes - 图21

An immutable representation of a set of Links.

LinkSets are created when a multi link on edgedb.Object is accessed via a [] operator.

Tuples

class

Tuple

Datatypes - 图22

Datatypes - 图23

Datatypes - 图24

An immutable value representing an EdgeDB tuple value.

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

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  1. r = client.query_single('''SELECT (1, 'a', [3])''')
  1. >>>
  1. r
  1. (1, 'a', [3])
  1. >>>
  1. len(r)
  1. 3
  1. >>>
  1. r[1]
  1. 'a'
  1. >>>
  1. r == (1, 'a', [3])
  1. True

Named Tuples

class

NamedTuple

Datatypes - 图25

Datatypes - 图26

Datatypes - 图27

An immutable value representing an EdgeDB named tuple value.

Instances of edgedb.NamedTuple generally behave similarly to namedtuple:

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  1. r = client.query_single('''SELECT (a := 1, b := 'a', c := [3])''')
  1. >>>
  1. r
  1. (a := 1, b := 'a', c := [3])
  1. >>>
  1. r.b
  1. 'a'
  1. >>>
  1. r[0]
  1. 1
  1. >>>
  1. r == (1, 'a', [3])
  1. True

Arrays

class

Array

Datatypes - 图28

Datatypes - 图29

Datatypes - 图30

An immutable value representing an EdgeDB array value.

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  1. r = client.query_single('''SELECT [1, 2, 3]''')
  1. >>>
  1. r
  1. [1, 2, 3]
  1. >>>
  1. len(r)
  1. 3
  1. >>>
  1. r[1]
  1. 2
  1. >>>
  1. r == [1, 2, 3]
  1. True

RelativeDuration

class

RelativeDuration

Datatypes - 图31

Datatypes - 图32

Datatypes - 图33

An immutable value represeting an EdgeDB cal::relative_duration value.

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  1. r = client.query_single('''SELECT <cal::relative_duration>"1 year 2 days 3 seconds"''')
  1. >>>
  1. r
  1. <edgedb.RelativeDuration "P1Y2DT3S">
  1. >>>
  1. r.months
  1. 12
  1. >>>
  1. r.days
  1. 2
  1. >>>
  1. r.microseconds
  1. 3000000

DateDuration

class

DateDuration

Datatypes - 图34

Datatypes - 图35

Datatypes - 图36

An immutable value represeting an EdgeDB cal::date_duration value.

  1. >>>
  1. import edgedb
  1. >>>
  1. client = edgedb.create_client()
  1. >>>
  1. r = client.query_single('''SELECT <cal::date_duration>"1 year 2 days"''')
  1. >>>
  1. r
  1. <edgedb.DateDuration "P1Y2D">
  1. >>>
  1. r.months
  1. 12
  1. >>>
  1. r.days
  1. 2