TypeDB 3.0 is live! Get started for free.

Python driver API reference

Connection

TypeDB

driver

static driver(address: str, credentials: Credentials, driver_options: DriverOptions) -> Driver

Creates a connection to TypeDB.

Input parameters
Name Description Type Default Value

address

Address of the TypeDB server.

str

credentials

The credentials to connect with.

Credentials

driver_options

The connection settings to connect with.

DriverOptions

Returns

Driver

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/connection/TypeDBDriver.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/connection/TypeDBCredential.adoc[]

DatabaseManager

Provides access to all database management methods.

all

all() -> List[Database]

Retrieves all databases present on the TypeDB server

Returns

List[Database]

Code examples
driver.databases.all()

contains

contains(name: str) -> bool

Checks if a database with the given name exists

Input parameters
Name Description Type Default Value

name

The database name to be checked

str

Returns

bool

Code examples
driver.databases.contains(name)

create

create(name: str) -> None

Create a database with the given name

Input parameters
Name Description Type Default Value

name

The name of the database to be created

str

Returns

None

Code examples
driver.databases.create(name)

get

get(name: str) -> Database

Retrieve the database with the given name.

Input parameters
Name Description Type Default Value

name

The name of the database to retrieve

str

Returns

Database

Code examples
driver.databases.get(name)

Database

Properties
Name Type Description

name

str

The database name as a string.

delete

delete() -> None

Deletes this database.

Returns

None

Code examples
database.delete()

schema

schema() -> str

Returns a full schema text as a valid TypeQL define query string.

Returns

str

Code examples
database.schema()

type_schema

type_schema() -> str

Returns the types in the schema as a valid TypeQL define query string.

Returns

str

Code examples
database.type_schema()

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/connection/Replica.adoc[]

UserManager

Provides access to all user management methods.

all

all() -> List[User]

Retrieves all users which exist on the TypeDB server.

Returns

List[User]

Code examples
driver.users.all()

contains

contains(username: str) -> bool

Checks if a user with the given name exists.

Input parameters
Name Description Type Default Value

username

The user name to be checked

str

Returns

bool

Code examples
driver.users.contains(username)

create

create(username: str, password: str) -> None

Create a user with the given name and password.

Input parameters
Name Description Type Default Value

username

The name of the user to be created

str

password

The password of the user to be created

str

Returns

None

Code examples
driver.users.create(username, password)

get

get(username: str) -> User | None

Retrieve a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to retrieve

str

Returns

User | None

Code examples
driver.users.get(username)

get_current_user

get_current_user() -> User | None

Retrieve the name of the user who opened the current connection.

Returns

User | None

Code examples
driver.users.get_current_user()

User

TypeDB user information

Properties
Name Type Description

name

str

Returns the name of this user.

delete

delete() -> None

Deletes a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to be deleted

Returns

None

Code examples
driver.users.delete(username)

update_password

update_password(password: str) -> None

Updates the password for this user.

Input parameters
Name Description Type Default Value

password_old

The current password of this user

password_new

The new password

Returns

None

Session

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/session/TypeDBSession.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/session/SessionType.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/session/TypeDBOptions.adoc[]

Transaction

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/transaction/TypeDBTransaction.adoc[]

TransactionType

This class is used to specify the type of transaction.

Examples
driver.transaction(database, TransactionType.READ)
Enum constants
Name Value

READ

0

SCHEMA

2

WRITE

1

is_read

is_read() -> bool
Returns

bool

is_schema

is_schema() -> bool
Returns

bool

is_write

is_write() -> bool
Returns

bool

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/transaction/QueryManager.adoc[]

Answer

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/answer/ConceptMapGroup.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/answer/ConceptMap.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/answer/ValueGroup.adoc[]

Promise

A Promise represents an asynchronous network operation.

The request it represents is performed immediately. The response is only retrieved once the Promise is resolved.

map

classmethod map(ctor: Callable[[U], T], raw: Callable[[], U]) -> Promise[T]
Returns

Promise[T]

resolve

resolve() -> T

Retrieves the result of the Promise.

Returns

T

Code examples
promise.resolve()

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/answer/Explainables.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/answer/Explainable.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/answer/Explanation.adoc[]

Concept

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/concept/ConceptManager.adoc[]

Concept

as_attribute

as_attribute() -> Attribute

Casts the concept to Attribute.

Returns

Attribute

Code examples
concept.as_attribute()

as_attribute_type

as_attribute_type() -> AttributeType

Casts the concept to AttributeType.

Returns

AttributeType

Code examples
concept.as_attribute_type()

as_entity

as_entity() -> Entity

Casts the concept to Entity.

Returns

Entity

Code examples
concept.as_entity()

as_entity_type

as_entity_type() -> EntityType

Casts the concept to EntityType.

Returns

EntityType

Code examples
concept.as_entity_type()

as_instance

as_instance() -> Instance

Casts the concept to Instance.

Returns

Instance

Code examples
concept.as_instance()

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
concept.as_relation()

as_relation_type

as_relation_type() -> RelationType

Casts the concept to RelationType.

Returns

RelationType

Code examples
concept.as_relation_type()

as_role_type

as_role_type() -> RoleType

Casts the concept to RoleType.

Returns

RoleType

Code examples
concept.as_role_type()

as_type

as_type() -> Type

Casts the concept to Type.

Returns

Type

Code examples
concept.as_type()

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
concept.as_value()

get_label

get_label() -> str

Get the label of the concept. If this is an Instance, return the label of the type of this instance (“unknown” if type fetching is disabled). If this is a Value, return the label of the value type of the value. If this is a Type, return the label of the type.

Returns

str

Code examples
concept.get_label()

is_attribute

is_attribute() -> bool

Checks if the concept is an Attribute.

Returns

bool

Code examples
concept.is_attribute()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
concept.is_attribute_type()

is_boolean

is_boolean() -> bool

Returns True if the value which this Concept holds is of type boolean or if this Concept is an AttributeType of type boolean. Otherwise, returns False.

Returns

bool

Code examples
concept.is_boolean()

is_date

is_date() -> bool

Returns True if the value which this Concept holds is of type date or if this Concept is an AttributeType of type date. Otherwise, returns False.

Returns

bool

Code examples
concept.is_date()

is_datetime

is_datetime() -> bool

Returns True if the value which this Concept holds is of type datetime or if this Concept is an AttributeType of type datetime. Otherwise, returns False.

Returns

bool

Code examples
concept.is_datetime()

is_datetime_tz

is_datetime_tz() -> bool

Returns True if the value which this Concept holds is of type datetime-tz or if this Concept is an AttributeType of type datetime-tz. Otherwise, returns False.

Returns

bool

Code examples
concept.is_datetime_tz()

is_decimal

is_decimal() -> bool

Returns True if the value which this Concept holds is of type decimal or if this Concept is an AttributeType of type decimal. Otherwise, returns False.

Returns

bool

Code examples
concept.is_decimal()

is_double

is_double() -> bool

Returns True if the value which this Concept holds is of type double or if this Concept is an AttributeType of type double. Otherwise, returns False.

Returns

bool

Code examples
concept.is_double()

is_duration

is_duration() -> bool

Returns True if the value which this Concept holds is of type duration or if this Concept is an AttributeType of type duration. Otherwise, returns False.

Returns

bool

Code examples
concept.is_duration()

is_entity

is_entity() -> bool

Checks if the concept is an Entity.

Returns

bool

Code examples
concept.is_entity()

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
concept.is_entity_type()

is_instance

is_instance() -> bool

Checks if the concept is a Instance.

Returns

bool

Code examples
concept.is_instance()

is_integer

is_integer() -> bool

Returns True if the value which this Concept holds is of type integer or if this Concept is an AttributeType of type integer. Otherwise, returns False.

Returns

bool

Code examples
concept.is_integer()

is_relation

is_relation() -> bool

Checks if the concept is a Relation.

Returns

bool

Code examples
concept.is_relation()

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
concept.is_relation_type()

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
concept.is_role_type()

is_string

is_string() -> bool

Returns True if the value which this Concept holds is of type string or if this Concept is an AttributeType of type string. Otherwise, returns False.

Returns

bool

Code examples
concept.is_string()

is_struct

is_struct() -> bool

Returns True if the value which this Concept holds is of type struct or if this Concept is an AttributeType of type struct. Otherwise, returns False.

Returns

bool

Code examples
concept.is_struct()

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
concept.is_type()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
concept.is_value()

try_get_boolean

try_get_boolean() -> bool | None

Returns a boolean value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

bool | None

Code examples
value.try_get_boolean()

try_get_date

try_get_date() -> date | None

Returns a timezone naive date value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

date | None

Code examples
value.try_get_date()

try_get_datetime

try_get_datetime() -> Datetime | None

Returns a timezone naive datetime value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Datetime | None

Code examples
value.try_get_datetime()

try_get_datetime_tz

try_get_datetime_tz() -> Datetime | None

Returns a timezone naive datetime_tz value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Datetime | None

Code examples
value.try_get_datetime_tz()

try_get_decimal

try_get_decimal() -> Decimal | None

Returns a decimal value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Decimal | None

Code examples
value.try_get_decimal()

try_get_double

try_get_double() -> float | None

Returns a double value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

float | None

Code examples
value.try_get_double()

try_get_duration

try_get_duration() -> Duration | None

Returns a timezone naive duration value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Duration | None

Code examples
value.try_get_duration()

try_get_iid

try_get_iid() -> str | None

Retrieves the unique id of the Concept. Returns None if absent.

Returns

str | None

Code examples
concept.try_get_iid()

try_get_integer

try_get_integer() -> int | None

Returns a integer value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

int | None

Code examples
value.try_get_integer()

try_get_label

try_get_label() -> str | None

Get the label of the concept. If this is an Instance, return the label of the type of this instance (None if type fetching is disabled). Returns None if type fetching is disabled. If this is a Value, return the label of the value type of the value. If this is a Type, return the label of the type.

Returns

str | None

Code examples
concept.try_get_label()

try_get_string

try_get_string() -> str | None

Returns a string value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

str | None

Code examples
value.try_get_string()

try_get_struct

try_get_struct() -> STRUCT | None

Returns a struct value of this Concept represented as a map from field names to values. If it’s not a Value or it has another type, raises an exception.

Returns

STRUCT | None

Code examples
value.try_get_struct()

try_get_value

try_get_value() -> VALUE | None

Retrieves the value which this Concept holds. Returns None if this Concept does not hold any value.

Returns

VALUE | None

Code examples
concept.try_get_value()

try_get_value_type

try_get_value_type() -> str | None

Retrieves the str` describing the value type fo this Concept. Returns None`` if absent.

Returns

str | None

Code examples
concept.try_get_value_type()

Schema

Type

Supertypes:

  • Concept

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
type_.is_type()

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/schema/Label.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/schema/ThingType.adoc[]

EntityType

Supertypes:

  • Type

Entity types represent the classification of independent objects in the data model of the business domain.

as_entity_type

as_entity_type() -> EntityType

Casts the concept to EntityType.

Returns

EntityType

Code examples
entity_type.as_entity_type()

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
entity_type.is_entity_type()

RelationType

Supertypes:

  • Type

Relation types (or subtypes of the relation root type) represent relationships between types. Relation types have roles.

Other types can play roles in relations if it’s mentioned in their definition.

A relation type must specify at least one role.

as_relation_type

as_relation_type() -> RelationType

Casts the concept to RelationType.

Returns

RelationType

Code examples
relation_type.as_relation_type()

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
relation_type.is_relation_type()

RoleType

Supertypes:

  • Type

Roles are special internal types used by relations. We can not create an instance of a role in a database. But we can set an instance of another type (role player) to play a role in a particular instance of a relation type.

Roles allow a schema to enforce logical constraints on types of role players.

as_role_type

as_role_type() -> RoleType

Casts the concept to RoleType.

Returns

RoleType

Code examples
role_type.as_role_type()

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
role_type.is_role_type()

AttributeType

Supertypes:

  • Type

Attribute types represent properties that other types can own.

Attribute types have a value type. This value type is fixed and unique for every given instance of the attribute type.

Other types can own an attribute type. That means that instances of these other types can own an instance of this attribute type. This usually means that an object in our domain has a property with the matching value.

Multiple types can own the same attribute type, and different instances of the same type or different types can share ownership of the same attribute instance.

as_attribute_type

as_attribute_type() -> AttributeType

Casts the concept to AttributeType.

Returns

AttributeType

Code examples
attribute.as_attribute_type()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
attribute.is_attribute_type()

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/schema/Annotation.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/schema/Transitivity.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/schema/ValueType.adoc[]

Data

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/data/Thing.adoc[]

Entity

Supertypes:

  • Instance

Instance of data of an entity type, representing a standalone object that exists in the data model independently.

Entity does not have a value. It is usually addressed by its ownership over attribute instances and/or roles played in relation instances.

as_entity

as_entity() -> Entity

Casts the concept to Entity.

Returns

Entity

Code examples
entity.as_entity()

get_iid

get_iid() -> str

Retrieves the unique id of the Entity.

Returns

str

Code examples
entity.get_iid()

get_type

get_type() -> EntityType

Retrieves the type which this Entity belongs to.

Returns

EntityType

Code examples
entity.get_type()

is_entity

is_entity() -> bool

Checks if the concept is an Entity.

Returns

bool

Code examples
entity.is_entity()

Relation

Supertypes:

  • Instance

Relation is an instance of a relation type and can be uniquely addressed by a combination of its type, owned attributes and role players.

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
relation.as_relation()

get_iid

get_iid() -> str

Retrieves the unique id of the Relation.

Returns

str

Code examples
relation.get_iid()

get_type

get_type() -> RelationType

Retrieves the type which this Relation belongs to.

Returns

RelationType

Code examples
relation.get_type()

is_relation

is_relation() -> bool

Checks if the concept is a Relation.

Returns

bool

Code examples
relation.is_relation()

Attribute

Supertypes:

  • Instance

Attribute is an instance of the attribute type and has a value. This value is fixed and unique for every given instance of the attribute type.

Attributes can be uniquely addressed by their type and value.

as_attribute

as_attribute() -> Attribute

Casts the concept to Attribute.

Returns

Attribute

Code examples
attribute.as_attribute()

get_boolean

get_boolean() -> bool

Returns a boolean value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

bool

Code examples
attribute.get_boolean()

get_date

get_date() -> date

Returns a timezone naive date value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

date

Code examples
attribute.get_date()

get_datetime

get_datetime() -> Datetime

Returns a timezone naive datetime value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Datetime

Code examples
attribute.get_datetime()

get_datetime_tz

get_datetime_tz() -> Datetime

Returns a timezone naive datetime_tz value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Datetime

Code examples
attribute.get_datetime_tz()

get_decimal

get_decimal() -> Decimal

Returns a decimal value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Decimal

Code examples
attribute.get_decimal()

get_double

get_double() -> float

Returns a double value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

float

Code examples
attribute.get_double()

get_duration

get_duration() -> Duration

Returns a timezone naive duration value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Duration

Code examples
attribute.get_duration()

get_integer

get_integer() -> int

Returns a integer value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

int

Code examples
attribute.get_integer()

get_string

get_string() -> str

Returns a string value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

str

Code examples
attribute.get_string()

get_struct

get_struct() -> Concept.STRUCT

Returns a struct value of the value concept that this attribute holds represented as a map from field names to values. If the value has another type, raises an exception.

Returns

Concept.STRUCT

Code examples
attribute.get_struct()

get_type

get_type() -> AttributeType

Retrieves the type which this Attribute belongs to.

Returns

AttributeType

Code examples
attribute.get_type()

get_value

get_value() -> Concept.VALUE

Retrieves the value which the Attribute instance holds.

Returns

Concept.VALUE

Code examples
attribute.get_value()

get_value_type

get_value_type() -> str

Retrieves the description of the value type of the value which the Attribute instance holds.

Returns

str

Code examples
attribute.get_value_type()

is_attribute

is_attribute() -> bool

Checks if the concept is an Attribute.

Returns

bool

Code examples
attribute.is_attribute()

Value

Supertypes:

  • Concept

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
value.as_value()

get

get() -> bool | int | float | Decimal | str | date | Datetime | Duration | Dict[str, Value | None]

Retrieves the value which this value concept holds.

Returns

bool | int | float | Decimal | str | date | Datetime | Duration | Dict[str, Value | None]

Code examples
value.get()

get_boolean

get_boolean() -> bool

Returns a boolean value of this value concept. If the value has another type, raises an exception.

Returns

bool

Code examples
value.get_boolean()

get_date

get_date() -> date

Returns a timezone naive date value of this value concept. If the value has another type, raises an exception.

Returns

date

Code examples
value.get_date()

get_datetime

get_datetime() -> Datetime

Returns a timezone naive datetime value of this value concept. If the value has another type, raises an exception.

Returns

Datetime

Code examples
value.get_datetime()

get_datetime_tz

get_datetime_tz() -> Datetime

Returns a timezone naive datetime_tz value of this value concept. If the value has another type, raises an exception.

Returns

Datetime

Code examples
value.get_datetime_tz()

get_decimal

get_decimal() -> Decimal

Returns a decimal value of this value concept. If the value has another type, raises an exception.

Returns

Decimal

Code examples
value.get_decimal()

get_double

get_double() -> float

Returns a double value of this value concept. If the value has another type, raises an exception.

Returns

float

Code examples
value.get_double()

get_duration

get_duration() -> Duration

Returns a timezone naive duration value of this value concept. If the value has another type, raises an exception.

Returns

Duration

Code examples
value.get_duration()

get_integer

get_integer() -> int

Returns a integer value of this value concept. If the value has another type, raises an exception.

Returns

int

Code examples
value.get_integer()

get_string

get_string() -> str

Returns a string value of this value concept. If the value has another type, raises an exception.

Returns

str

Code examples
value.get_string()

get_struct

get_struct() -> Dict[str, Value | None]

Returns a struct value of this value concept represented as a map from field names to values. If the value has another type, raises an exception.

Returns

Dict[str, Value | None]

Code examples
value.get_struct()

get_type

get_type() -> str

Retrieves the str describing the value type of this Value concept.

Returns

str

Code examples
value.get_type()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
value.is_value()

Logic

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/logic/LogicManager.adoc[]

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::api-ref::partial$python/logic/Rule.adoc[]

Errors

TypeDBDriverException

Supertypes:

  • RuntimeError

Exceptions raised by the driver.

Examples
try:
    transaction.commit()
except TypeDBDriverException as err:
    print("Error:", err)