Officially out now: The TypeDB 3.0 Roadmap

Python driver

The Python driver was developed by the TypeDB team to enable TypeDB support for Python software and developers.

The GitHub repository with the driver’s source code and release notes.

The default package manager’s page about the driver’s package.

Install

See the Version Compatibility table to check what versions of TypeDB and Python driver are compatible.

Supported Python versions: from 3.8 to 3.11. For Linux: the minimum version of glibc is 2.25.0.

To install TypeDB Python driver:

pip install typedb-driver
See the command for older versions (<2.24.0)
pip install typedb-client

Checking your installation

You should be able to import the TypeDB driver as follows:

import typedb.driver

On Windows, the import may fail with ImportError: DLL load failed. If it does, it means your system is missing the Microsoft Visual C++ redistributable matching your Python version. To fix the issue, download and install the package.

Quickstart

See below a short example of Python code that connects to a local TypeDB Core, creates a database named access-management-db, defines a schema, inserts some data, and then reads it.

from typedb.driver import TypeDB, SessionType, TransactionType

DB_NAME = "access-management-db"
SERVER_ADDR = "127.0.0.1:1729"

with TypeDB.core_driver(SERVER_ADDR) as driver:
    if driver.databases.contains(DB_NAME):
        driver.databases.get(DB_NAME).delete()
    driver.databases.create(DB_NAME)

    with driver.session(DB_NAME, SessionType.SCHEMA) as session:
        with session.transaction(TransactionType.WRITE) as tx:
            tx.query.define("define person sub entity;")
            tx.query.define("define name sub attribute, value string; person owns name;")
            tx.commit()

    with driver.session(DB_NAME, SessionType.DATA) as session:
        with session.transaction(TransactionType.WRITE) as tx:
            tx.query.insert("insert $p isa person, has name 'Alice';")
            tx.query.insert("insert $p isa person, has name 'Bob';")
            tx.commit()
        with session.transaction(TransactionType.READ) as tx:
            results = tx.query.fetch("match $p isa person; fetch $p: name;")
            for json in results:
                print(json)

For more code examples, see the Tutorial and API reference links below.

Learn more

This tutorial will help you learn how to use the Python driver.

Driver API reference for the Python language.

Any questions about the driver after reading the documentation? Feel free to ask on our Discord community server.

Version Compatibility

Python driver Protocol encoding version TypeDB Core TypeDB Cloud Python

2.28.0

3

2.28.0

2.28.0

3.8 to 3.11

2.27.0

3

2.27.0

2.27.0

3.8 to 3.11

2.26.6

3

2.26.6

2.26.6

3.8 to 3.11

2.25.8

3

2.25.7

2.25.7

3.9 to 3.11

2.24.15

2

2.24.17

2.24.17

3.9 to 3.11

See older versions
Python driver Protocol encoding version TypeDB Core TypeDB Cloud Python

2.18.0 to 2.18.2

1

2.18.0 to 2.23.0

2.18.0 to 2.23.0

>= 3.6

2.17.0

N/A

2.17.0

2.17.0

>= 3.6

2.16.1

N/A

2.16.1

2.16.1

>= 3.6

2.12.0 to 2.14.3

N/A

2.12.0 to 2.15

2.13.0 to 2.15

>= 3.6

2.9.0 to 2.11.1

N/A

2.9.0 to 2.11.1

2.9.0 to 2.11.2

>= 3.6

2.8.0

N/A

2.8.0

N/A

>= 3.6

2.6.0 to 2.6.3

N/A

2.6.0 to 2.7.1

N/A

>= 3.6

2.4.0 to 2.5.0

N/A

2.1.2 to 2.5.0

2.5.0

>= 3.6

2.2.0

N/A

2.1.2 to 2.5.0

2.1.2 to 2.3.0

>= 3.6

2.1.1

N/A

2.1.2

2.1.2

>= 3.6

2.1.0

N/A

2.1.0

2.1.0

>= 3.6

2.0.1

N/A

2.0.2

2.0.2

>= 3.6

2.0.0

N/A

2.0.0 to 2.0.1

2.0.0 to 2.0.1

>= 3.6

1.8.0

N/A

1.8.0 to 1.8.4

N/A

>= 3.5, < 3.8

Provide Feedback