Code Monkey home page Code Monkey logo

typedb-driver-python's Introduction

THIS REPOSITORY HAS BEEN ARCHIVED. Please visit: @vaticle/typedb-driver/python


TypeDB Client for Python

Factory GitHub release Discord Discussion Forum Stack Overflow Stack Overflow

Client Architecture

To learn about the mechanism that a TypeDB Client uses to set up communication with databases running on the TypeDB Server, refer to TypeDB > Client API > Overview.

API Reference

To learn about the methods available for executing queries and retrieving their answers using Client Python, refer to TypeDB > Client API > Python > API Reference.

Concept API

To learn about the methods available on the concepts retrieved as the answers to TypeQL queries, refer to TypeDB > Concept API > Overview

Install TypeDB Client for Python through Pip

pip install typedb-client

If multiple Python versions are available, you may wish to use

pip3 install typedb-client

In your python program, import from typedb.client:

from typedb.client import *

client = TypeDB.core_client(address=TypeDB.DEFAULT_ADDRESS)

typedb-driver-python's People

Contributors

2xyo avatar adammichaelwood avatar alexjpwalker avatar dmikhalin avatar dmitrii-ubskii avatar flyingsilverfin avatar grabl avatar haikalpribadi avatar jamesreprise avatar jmsfltchr avatar krishnangovindraj avatar lolski avatar lriuui0x0 avatar shiladitya-mukherjee avatar vmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typedb-driver-python's Issues

Getting GRPC error after idle for some time

@flyingsilverfin raising the bug as discussed in stackoverflow.

Description

While trying to create a session to grakn keyspace,after the grakn server is idle for sometime, i am getting session error.

I am using a python 3.6 application which has grakn-client of version 1.6.0 and the grakn server version is 1.6.0. I am getting this error intermittently. Only after the grakn server is idle for some time and on the first try. Trying to connect again after this error, with create the sessionid.

Could not obtain sessionId for keyspace abc

The error generated by python grakn-client is
<_Rendezvous of RPC that terminated with: status = StatusCode.UNAVAILABLE details = “OS Error” debug_error_string = “{“created”:”@1592293927.075671633",“description”:“Error received from peer”,“file”:“src/core/lib/surface/call.cc”,“file_line”:1017,“grpc_message”:“OS Error”,“grpc_status”:14}"
Also we are getting this error while trying to retrive all keyspace name list. client.keyspaces().retrieve() is also throwing this error intermittendly

Environment

  1. OS (where Grakn server runs): Ubuntu 18.04
  2. Grakn version (and platform): Grakn Core 1.6.0
  3. Grakn client-python version: grakn-client 1.6.0
  4. Python version: 3.6
  5. Other environment details: Commonly seen this error in docker env

Reproducible Steps

  1. Try to create a session after idle for long time.

Expected Output

No error

Actual Output

{ <_Rendezvous of RPC that terminated with: status = StatusCode.UNAVAILABLE details = “OS Error” debug_error_string = “{“created”:”@1592293927.075671633",“description”:“Error received from peer”,“file”:“src/core/lib/surface/call.cc”,“file_line”:1017,“grpc_message”:“OS Error”,“grpc_status”:14} }

Type annotations

Problem to Solve

Once Python 2 support is removed, we should implement proper type annotations/hinting throughout the client.

Current Workaround

Incomplete usage of __init__.__annotations__ = {...}

Proposed Solution

TODO figure out best solution, mypy, typing in python etc. Not sure what the current state of things is!

Additional Information

Internal gRPC error when querying for data

(this bug only happens sometimes)

Description

I am testing client python with different read queries. Before running into the errors described below, the query was working fine. But after running it twice, I now get the Exceptions below.

Environment

  1. OS: Mac OS 10.14
  2. Grakn version: Grakn Core 2.0.0-alpha
  3. Grakn client-python version: client-python 2.0.0-alpha-4
  4. Python version: 3.9

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Run this grakn distribution: https://www.dropbox.com/s/1y3ophwlv6xyg2z/grakn-2.0-alpha-tomas-20210109.zip?dl=0
  2. In a terminal run python, and run:
from grakn.client import GraknClient, SessionType, TransactionType
client = GraknClient("localhost:1729")
session = client.session("biograkn_covid_16", SessionType.DATA)
tx = session.transaction(TransactionType.READ)
answer_iterator = tx.query().match("match $x isa protein, has uniprot-id $uid; get $uid;")
for answer in answer_iterator:
	person = answer.get("uid")
	print("Retrieved protein with id " + person.get_iid())
  1. After some data gets returned, I see this error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grakn/rpc/stream.py", line 57, in __next__
    return next(self)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grakn/rpc/stream.py", line 50, in __next__
    res = self._transaction._fetch(self._request_id)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grakn/rpc/transaction.py", line 136, in _fetch
    response = next(self._response_iterator)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 416, in __next__
    return self._next()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 778, in _next
    operating = self._call.operate(
  File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 277, in grpc._cython.cygrpc.IntegratedCall.operate
  File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 102, in grpc._cython.cygrpc._operate_from_integrated_call
  File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 110, in grpc._cython.cygrpc._operate_from_integrated_call
  File "src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi", line 57, in grpc._cython.cygrpc._raise_call_error_no_metadata
ValueError: Internal gRPC call error 8. Please report to https://github.com/grpc/grpc/issues
  1. Then I run again:
answer_iterator = tx.query().match("match $x isa protein, has uniprot-id $uid; get $uid;")
for answer in answer_iterator:
	person = answer.get("uid")
	print("Retrieved protein with id " + person.get_iid())

And I see this error:

Exception in thread Thread-29:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "src/python/grpcio/grpc/_cython/_cygrpc/thread.pyx.pxi", line 53, in grpc._cython.cygrpc._run_with_context._run
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 1238, in channel_spin
    call_completed = event.tag(event)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 166, in handle_event
    callbacks = _handle_event(event, state, response_deserializer)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 131, in _handle_event
    state.due.remove(operation_type)
KeyError: 5

Expected Output

I expect data to be returned in the console.

Actual Output

The first error returns a ValueError: Internal gRPC call error 8., and the second time I am returned with an Exception in thread Thread-29:

Additional information

image

After this error, I close both the session and transaction. After I open a new session, I try to open a new transaction. However, this hangs and nothing happens:
image

grakn_protocol/protobuf/concept_pb2 throws DeprecationWarning: Create unlinked descriptors is going to go away.

Description

When running client-python, the following DeprecationWarning is raised at a number of places in grakn_protocol/protobuf/options_pb2

/Users/rkm916/Library/Caches/pypoetry/virtualenvs/grakn-dev-utils-UF7XQuoC-py3.9/lib/python3.9/site-packages/grakn_protocol/protobuf/options_pb2.py:84: DeprecationWarning: Call to deprecated create function FieldDescriptor(). Note: Create unlinked descriptors is going to go away. Please use get/find descriptors from generated code or query the descriptor_pool.

Environment

  1. OS (where Grakn server runs): Mac OS 10
  2. Grakn version (and platform): Grakn Core 8.0.0-alpha-9
  3. Grakn client-python version: client-python 2.0.0-alpha-10
  4. Python version: 3.91

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Running code that calls the file mentioned above should reproduce the warning

Expected Output

Actual Output

See warning above

Deduplicate Error Messages

Description

Right now, users of client-python always get a stacked error message:

In [14]: s.transaction().write()
---------------------------------------------------------------------------
_Rendezvous                               Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py in send_receive(self, request)
    208             self._add_request(request)
--> 209             response = next(self._response_iterator)
    210         except Exception as e: # specialize into different gRPC exceptions?

/usr/local/lib/python3.7/site-packages/grpc/_channel.py in __next__(self)
    387     def __next__(self):
--> 388         return self._next()
    389 

/usr/local/lib/python3.7/site-packages/grpc/_channel.py in _next(self)
    381                 elif self._state.code is not None:
--> 382                     raise self
    383 

_Rendezvous: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace."
	debug_error_string = "{"created":"@1591890637.307174000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace.","grpc_status":14}"
>

During handling of the above exception, another exception occurred:

GraknError                                Traceback (most recent call last)
<ipython-input-14-bad13dd12b5f> in <module>()
----> 1 s.transaction().write()

/usr/local/lib/python3.7/site-packages/grakn/client.py in write(self)
    104 
    105     def write(self):
--> 106         transaction_service = TransactionService(self._session_id, _TxType.WRITE, self._transaction_rpc_constructor)
    107         return Transaction(transaction_service)
    108 

/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py in __init__(self, session_id, tx_type, transaction_endpoint)
     37         # open the transaction with an 'open' message
     38         open_req = RequestBuilder.open_tx(session_id, tx_type)
---> 39         self._communicator.send_receive(open_req)
     40     __init__.__annotations__ = {'tx_type': enums.TxType}
     41 

/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py in send_receive(self, request)
    211             # invalidate this communicator, functionally this occurs automatically on exception (iterator not usable anymore)
    212             self._closed = True
--> 213             raise GraknError("Server/network error: {0}\n\n generated from request: {1}".format(e, request))
    214 
    215         if response is None:

GraknError: Server/network error: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace."
	debug_error_string = "{"created":"@1591890637.307174000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace.","grpc_status":14}"
>

 generated from request: open_req {
  sessionId: "testing0037b22d-67ce-4df3-8ee3-2733989855ad"
  type: WRITE
}

Ideally, we would only throw a single exception with the server side exception/error message within it.

Environment

Grakn Core any version with any client-python since approx 1.4

Reproducible Steps

Cause any error in client-python

Expected Output

Single, neatly wrapped exception with the server's error

Actual Output

Two client-side stack traces! And buried within these are the server error message, duplicated twice.

Additional information

We could mirror the style of errors occuring in the server, where a specific class of RuntimeException is caught at the very top level of everything, and printed out without a stack trace, just error message.

Bazel build fails in Python 3.8.7 and 3.9.1

Description

bazel build //... fails with the error: "TypeError: expected string or bytes-like object" (running python setup.py egg_info)

Environment

  1. OS (where TypeDB server runs): Mac OS 11 Big Sur
  2. TypeDB version (and platform): N/A
  3. TypeDB client-python version: client-python==2.0.0a5
  4. Python version: 3.8.7 and 3.9.1

Reproducible Steps

bazel build //...

Expected Output

Project should build

Actual Output

It fails with the error: "TypeError: expected string or bytes-like object" (running python setup.py egg_info)

Additional information

pip3 install -r requirements_dev.txt seems to succeed in these Python versions. So I think the issue is not with pip itself but with Bazel's implementation of it.

ModuleNotFoundError: No module named 'grakn.client'; 'grakn' is not a package

Description

I've installed grakn-client through pip like mentioned on pypi or in the grakn docs. Installation worked successfully but after importing
from grakn.client import GraknClient
I get the Error:
ModuleNotFoundError: No module named 'grakn.client'; 'grakn' is not a package

Environment

  1. Windows 10 Pro - 64 Bit
  2. Grakn Core 1.7.1 hosted on premise on Ubuntu 18.04.4 LTS
  3. client-python 1.7.2 and for testing previous version while getting the same error
  4. Python version: first 3.8 then 3.6.8 and now through conda 3.7.7 everytime getting the same error
  5. Other environment details:

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. install python 3.6.8 on windows 10 Pro 64 Bit
  2. execute pip install grakn-client
  3. create python file and just add from grakn.client import GraknClient

Expected Output

Nothing.

Actual Output

Traceback (most recent call last): File "c:/Users/Johannes/testing/grakn.py", line 1, in <module> from grakn.client import GraknClient File "c:\Users\Johannes\testing\grakn.py", line 1, in <module> from grakn.client import GraknClient ModuleNotFoundError: No module named 'grakn.client'; 'grakn' is not a package

Additional information

Grakn-client 1.7.2 needs to be compatible with protobuf 3.8.0 and grpcio 1.24.3 or newer

Description

When installing grakn-client, the following message shows up:

ERROR: tensorflow 2.1.0 has requirement protobuf>=3.8.0, but you'll have protobuf 3.6.1 which is incompatible.
ERROR: tensorflow-hub 0.8.0 has requirement protobuf>=3.8.0, but you'll have protobuf 3.6.1 which is incompatible.
ERROR: tensorboard 2.1.1 has requirement grpcio>=1.24.3, but you'll have grpcio 1.24.1 which is incompatible.
ERROR: ray 0.8.5 has requirement protobuf>=3.8.0, but you'll have protobuf 3.6.1 which is incompatible.

Environment

  1. OS (where Grakn server runs): Ubuntu 18.04
  2. Grakn version (and platform): 1.7
  3. Grakn client-python version: 1.7.2
  4. Python version: 3.7
  5. Other environment details:

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. pip install -U grakn-client==1.7.2

Expected Output

no error messages indicating incompatibility

Actual Output

ERROR: tensorflow 2.1.0 has requirement protobuf>=3.8.0, but you'll have protobuf 3.6.1 which is incompatible.
ERROR: tensorflow-hub 0.8.0 has requirement protobuf>=3.8.0, but you'll have protobuf 3.6.1 which is incompatible.
ERROR: tensorboard 2.1.1 has requirement grpcio>=1.24.3, but you'll have grpcio 1.24.1 which is incompatible.
ERROR: ray 0.8.5 has requirement protobuf>=3.8.0, but you'll have protobuf 3.6.1 which is incompatible.

Additional information

Python client API: .transaction.execute() method fails

Description

In Python client API, .transaction.execute() produces the error AttributeError: 'Transaction' object has no attribute 'execute'

Environment

  1. OS (where Grakn server runs): Mac OS Mojave 10.14.6
  2. Grakn version (and platform): Grakn Core 1.8.1
  3. Grakn client-python version: client-python 1.8.1
  4. Python version: 3.7.5

Reproducible Steps

in terminal:

grakn server start
grakn console -k socialnetwork --f schema.gql
grakn console -k socialnetwork --f data.gql

in Python:

client = GraknClient(uri="localhost:48555")
from grakn.client import GraknClient
with client.session(keyspace="socialnetwork") as session:
    with session.transaction().read() as read_transaction:   
         answer_iterator = read_transaction.execute(query="match $x sub person; get; limit 1;")
        

Expected Output

Expected answer_iterator to be an iterator yielding the 'person' type

Actual Output

AttributeError: 'Transaction' object has no attribute 'execute'

Additional info

  • The get query docs refer to the execute method only for java and the query method for the node and python APIs
  • However the Python API docs include examples of using the execute method

Random gRPC error: cancelled before receiving half close

Description

Similar to issue #17

When inserting data using python client, random gRPC errors occur

Environment

  1. OS (where Grakn server runs): Mac OS Mojave 10.14.5
  2. Grakn version (and platform): docker graknlabs/grakn:1.5.3
  3. Grakn client-python version: client-python 1.5.3
  4. Python version: 3.7.2

Reproducible Steps

Error random, but when inserting data using phone call examples, one might run into this error.

Seems to be happening when creating a new transaction.

Expected Output

No error.

Actual Output

erver/network error: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "null. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1559448052.745006000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"null. Please check server logs for the stack trace.","grpc_status":2}"
>

 generated from request: open_req {
  sessionId: "dh31abea9bc-7ba7-47e2-a776-05bf8c9a9499"
  type: WRITE
}

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 156, in send
    response = next(self._response_iterator)
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 364, in __next__
    return self._next()
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 358, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "null. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1559448052.745006000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"null. Please check server logs for the stack trace.","grpc_status":2}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "migrate.py", line 31, in build_phone_call_graph
    load_data_into_grakn(input, session)
  File "migrate.py", line 40, in load_data_into_grakn
    with session.transaction().write() as transaction:
  File "/usr/local/lib/python3.7/site-packages/grakn/client.py", line 106, in write
    transaction_service = TransactionService(self._session_id, _TxType.WRITE, self._transaction_rpc_constructor)
  File "/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 39, in __init__
    self._communicator.send(open_req)
  File "/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 160, in send
    raise GraknError("Server/network error: {0}\n\n generated from request: {1}".format(e, request))
grakn.exception.GraknError.GraknError: Server/network error: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "null. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1559448052.745006000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"null. Please check server logs for the stack trace.","grpc_status":2}"
>

 generated from request: open_req {
  sessionId: "dh31abea9bc-7ba7-47e2-a776-05bf8c9a9499"
  type: WRITE
}


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "migrate.py", line 303, in <module>
    build_phone_call_graph(inputs)
  File "migrate.py", line 34, in build_phone_call_graph
    raise
  File "/usr/local/lib/python3.7/site-packages/grakn/client.py", line 88, in __exit__
    self.close()
  File "/usr/local/lib/python3.7/site-packages/grakn/client.py", line 81, in close
    self._stub.close(close_session_req)
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 533, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "null. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1559448052.748124000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"null. Please check server logs for the stack trace.","grpc_status":2}"
>

Logs from grakn server:

[grpc-default-executor-4] ERROR g.c.s.r.SessionService$TransactionListener - Runtime Exception in RPC TransactionListener: 
io.grpc.StatusRuntimeException: CANCELLED: cancelled before receiving half close
	at io.grpc.Status.asRuntimeException(Status.java:517)
	at io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener.onCancel(ServerCalls.java:272)
	at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.closed(ServerCallImpl.java:293)
	at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1Closed.runInContext(ServerImpl.java:741)
	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Failure to insert relations with core 1.5.6

Description

Upgrade incompatibility: The same codebase targeting Core 1.5.3 inserts relations correctly but fails to do so when targeting Core 1.5.6.

Environment

  1. OS (where Grakn server runs): Ubuntu 18.04 LTS in Docker
  2. Grakn version (and platform): Grakn Core 1.5.6
  3. Grakn client-python version: client-python 1.5.3
  4. Python version: 3.7
  5. Other environment details: Docker

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Insert entities
  2. Insert relations between entities
  3. Query for relations (via console or workbase)
  4. Error: Query finds no relations

Expected Output

Both entities and relations are inserted.

Actual Output

Entities and their attributes are inserted but no relations are inserted.

Additional information

No errors are shown in the server logs. No stack-traces occur client-side.

Provide a method for checking if a transaction is open

Problem to Solve

At the moment, there is no straight forward way of checking whether a transaction is still open.

Current Workaround

Run some basic query and see if a Transaction is already closed error is returned.

Proposed Solution

Expose is_open on transaction

Updates based on new changes in 1.5

This issue contains the collection of changes that need to be made in Client Python in order to keep it in sync with changes introduced in Grakn 1.5.

  • creating a transaction: session.transaction().read();and session.transaction().write();
  • instantiation of the Grakn client to be consistent with client Java (@flyingsilverfin @vmax please discuss and clarify this change)
  • closing a client: client.close();
  • relationship > relation

Make our tests unzip Grakn, run it, and shut it down when done

Problem to Solve

Our current tests are not CI-friendly because they don't run Grakn. To run them locally, we have to have a Grakn process running in the background.

Current Workaround

To run them locally, we have to have a Grakn process running in the background.

Proposed Solution

Make our tests unzip Grakn, run it, and shut it down when done.

Dependency issue in KDE Neon

OS: KDE Neon 5.18.5 (Ubuntu 18.04 LTS); 5.3.0-51-generic
CPython: 3.8.2, using Pyenv 1.2.18 and Poetry 1.0.5

➜ poetry show --tree
pytest 5.4.2 pytest: simple powerful testing with Python
├── atomicwrites >=1.0
├── attrs >=17.4.0
├── colorama *
├── more-itertools >=4.0.0
├── packaging *
│ ├── pyparsing >=2.0.2
│ └── six *
├── pluggy >=0.12,<1.0
├── py >=1.5.0
└── wcwidth *

When I go to install grakn-client with "poetry add grakn-client" or "pip install grakn-client", I get the following error. This occurs with the project's Poetry virtualenv enabled and disabled.

ERROR: Command errored out with exit status 1: command: /home/user/Development/Projects/Python/KnowledgeGraph/.venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-logm33dw/grakn-client/setup.py'"'"'; file='"'"'/tmp/pip-install-logm33dw/grakn-client/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-p8y0pq8l cwd: /tmp/pip-install-logm33dw/grakn-client/ Complete output (11 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/user/Development/Projects/Python/KnowledgeGraph/.venv/lib/python3.8/site-packages/setuptools/init.py", line 19, in <module> from setuptools.dist import Distribution File "/home/user/Development/Projects/Python/KnowledgeGraph/.venv/lib/python3.8/site-packages/setuptools/dist.py", line 34, in <module> from setuptools import windows_support File "/home/user/Development/Projects/Python/KnowledgeGraph/.venv/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module> import ctypes File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/ctypes/init.py", line 7, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

The install always fails on enum-compat. Grakn-client attempts to install enum-compat==0.0.2, even if 0.0.3 (which installs fine) is already present.

Deploy latest master to our private pypi registry

For our other repositories, such as docs and examples to depend on the latest master of client-python in a conventional way, we need client-python to be deployed to our private pypi registry on every commit made on the master branch.

Transaction is not closed on the client when it fails on the server

Description

When a transaction fails with an exception (on the server), it is not closed on the client.

Environment

  1. OS (where Grakn server runs): Mac OS 10.14.6
  2. Grakn version (and platform): Grakn Core 1.5.9
  3. Grakn client-python version: client-python 1.5.4
  4. Python version: 3.7.0

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Open a client, session and transaction
  2. run transaction.query('match typo');
  3. Receive an exception (expectedly)
  4. run transaction.query('match whatever');

Expected Output

Receive an exception saying that the transaction has already been closed.

Actual Output

Nothing happens

Provide __str__ implementations for Client Objects

Problem to Solve

The client would be more user friendly and faster to interactively work with if all of the classes defined provide a nice __str__() representation. For instance, a Concept being printed would show its base type and ID (local information) rather than a memory address, Answers could print the concept maps/list/sets and explanations in string format, transaction could show the type, session could show the keyspace etc.

Current Workaround

Manually print out by calling specific methods to retrieve desired information

Proposed Solution

  • Implement __str__() to print object contents better

Additional Information

Client Python: file structure naming is unclear

To use the class Concept in Python it is necessary to import as follows:

from grakn.service.Session.Concept import Concept

is_a_concept = isInstance(my_concept, Concept.Concept)

From a user perspective this is confusing since there is a package called Concept, containing a file called Concept, containing a class called Concept.

I believe ideal best practice would be to use lower case names for packages, and that they should be named according to a summary of their content. I don't know whether this would conflict with our naming across our other drivers but something should be done to limit the confusion here if possible.

Check if we still need to use Python 3.6.10 in CI

Problem to Solve

We currently set the Python environment to version 3.6.10 with a pyenv command in automation.yml. But most users will be on Python 3.8 or 3.9 by now.

Proposed Solution

Try using Python 3.8 (or whatever is the standard when this issue is tackled).

Additional Information

We would ideally use whatever Python is installed in Grabl, thus eliminating the need for a pyenv call in this Grabl CI file.

AttributeError: type object 'GraknClient' has no attribute 'core'

Description

calling GraknClient.core("localhost:1729") fails

Environment

  1. OS (where Grakn server runs): Mac OS 10
  2. Grakn version (and platform): Grakn core 2.0
  3. Grakn client-python version: client-python 2.0.0a6
  4. Python version: 3.9

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. install grakn, the grakn python client
  2. open python
  3. from grakn.client import *
  4. client = GraknClient.core("localhost:1729")

Expected Output

None

Actual Output

AttributeError: type object 'GraknClient' has no attribute 'core'

Additional information

help(GraknClient) shows that the 'core' method is indeed missing

pip3 install grakn-client fails (on Windows 10)

Description

pip3 install grakn-client fails to install Python client

Environment

  1. OS (where Grakn server runs): Windows 10 (Linux Subsystem: Ubuntu)
  2. Grakn version (and platform): Grakn Core 1.6.1 on Ubuntu
  3. Grakn client-python version: Grakn Client 1.6.0
  4. Python version: 3.8
  5. Other environment details: Visual Studio Community 16.4.2

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. pip3 install grakn-client

Expected Output

Installed

Actual Output

Collecting grakn-client
  Using cached https://files.pythonhosted.org/packages/d5/1b/3175ae4c5cc4c039073533aae0e1d25aea0acdea3c29787b3ddfda8c970f/grakn-client-1.6.0.tar.gz
Collecting grpcio==1.16.0 (from grakn-client)
  Using cached https://files.pythonhosted.org/packages/be/84/9afa550ae7bfc65a7150f66ecdbf267617a2d584d9f845b4ef7d026a24ad/grpcio-1.16.0.tar.gz
Collecting protobuf==3.6.1 (from grakn-client)
  Using cached https://files.pythonhosted.org/packages/77/78/a7f1ce761e2c738e209857175cd4f90a8562d1bde32868a8cd5290d58926/protobuf-3.6.1-py2.py3-none-any.whl
Collecting six==1.11.0 (from grakn-client)
  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting enum-compat==0.0.2 (from grakn-client)
  Using cached https://files.pythonhosted.org/packages/95/6e/26bdcba28b66126f66cf3e4cd03bcd63f7ae330d29ee68b1f6b623550bfa/enum-compat-0.0.2.tar.gz
Requirement already satisfied: setuptools in c:\users\michael\projects\graknworkbench\venv\lib\site-packages\setuptools-40.8.0-py3.8.egg (from protobuf==3.6.1->grakn-client) (40.8.0)
Installing collected packages: six, grpcio, protobuf, enum-compat, grakn-client
  Running setup.py install for grpcio ... error
    Complete output from command C:\Users\Michael\Projects\GraknWorkbench\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Michael\\AppData\\Local\\Temp\\pip-install-xguw__my\\grpcio\\setup.py';f=getattr(tokenize, 'open', open)(__file__)
;code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Michael\AppData\Local\Temp\pip-record-86jkdfzm\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\Michael\Projects\
GraknWorkbench\venv\include\site\python3.8\grpcio:
    Found cython-generated files...
    running install
    running build
    running build_py
    running build_project_metadata
    creating python_build
    creating python_build\lib.win32-3.8
    creating python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_auth.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_channel.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_common.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_grpcio_metadata.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_interceptor.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_plugin_wrapping.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_server.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\_utilities.py -> python_build\lib.win32-3.8\grpc
    copying src\python\grpcio\grpc\__init__.py -> python_build\lib.win32-3.8\grpc
    creating python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\implementations.py -> python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\interfaces.py -> python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\utilities.py -> python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\_client_adaptations.py -> python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\_metadata.py -> python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\_server_adaptations.py -> python_build\lib.win32-3.8\grpc\beta
    copying src\python\grpcio\grpc\beta\__init__.py -> python_build\lib.win32-3.8\grpc\beta
    creating python_build\lib.win32-3.8\grpc\experimental
    copying src\python\grpcio\grpc\experimental\gevent.py -> python_build\lib.win32-3.8\grpc\experimental
    copying src\python\grpcio\grpc\experimental\session_cache.py -> python_build\lib.win32-3.8\grpc\experimental
    copying src\python\grpcio\grpc\experimental\__init__.py -> python_build\lib.win32-3.8\grpc\experimental
    creating python_build\lib.win32-3.8\grpc\framework
    copying src\python\grpcio\grpc\framework\__init__.py -> python_build\lib.win32-3.8\grpc\framework
    creating python_build\lib.win32-3.8\grpc\_cython
    copying src\python\grpcio\grpc\_cython\__init__.py -> python_build\lib.win32-3.8\grpc\_cython
    creating python_build\lib.win32-3.8\grpc\framework\common
    copying src\python\grpcio\grpc\framework\common\cardinality.py -> python_build\lib.win32-3.8\grpc\framework\common
    copying src\python\grpcio\grpc\framework\common\style.py -> python_build\lib.win32-3.8\grpc\framework\common
    copying src\python\grpcio\grpc\framework\common\__init__.py -> python_build\lib.win32-3.8\grpc\framework\common
    creating python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\abandonment.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\callable_util.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\future.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\logging_pool.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\stream.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\stream_util.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    copying src\python\grpcio\grpc\framework\foundation\__init__.py -> python_build\lib.win32-3.8\grpc\framework\foundation
    creating python_build\lib.win32-3.8\grpc\framework\interfaces
    copying src\python\grpcio\grpc\framework\interfaces\__init__.py -> python_build\lib.win32-3.8\grpc\framework\interfaces
    creating python_build\lib.win32-3.8\grpc\framework\interfaces\base
    copying src\python\grpcio\grpc\framework\interfaces\base\base.py -> python_build\lib.win32-3.8\grpc\framework\interfaces\base
    copying src\python\grpcio\grpc\framework\interfaces\base\utilities.py -> python_build\lib.win32-3.8\grpc\framework\interfaces\base
    copying src\python\grpcio\grpc\framework\interfaces\base\__init__.py -> python_build\lib.win32-3.8\grpc\framework\interfaces\base
    creating python_build\lib.win32-3.8\grpc\framework\interfaces\face
    copying src\python\grpcio\grpc\framework\interfaces\face\face.py -> python_build\lib.win32-3.8\grpc\framework\interfaces\face
    copying src\python\grpcio\grpc\framework\interfaces\face\utilities.py -> python_build\lib.win32-3.8\grpc\framework\interfaces\face
    copying src\python\grpcio\grpc\framework\interfaces\face\__init__.py -> python_build\lib.win32-3.8\grpc\framework\interfaces\face
    creating python_build\lib.win32-3.8\grpc\_cython\_cygrpc
    copying src\python\grpcio\grpc\_cython\_cygrpc\__init__.py -> python_build\lib.win32-3.8\grpc\_cython\_cygrpc
    creating python_build\lib.win32-3.8\grpc\_cython\_credentials
    copying src\python\grpcio\grpc\_cython\_credentials\roots.pem -> python_build\lib.win32-3.8\grpc\_cython\_credentials
    running build_ext
    Found cython-generated files...
    building 'grpc._cython.cygrpc' extension
    creating python_build\temp.win32-3.8
    creating python_build\temp.win32-3.8\Release
    creating python_build\temp.win32-3.8\Release\src
    creating python_build\temp.win32-3.8\Release\src\python
    creating python_build\temp.win32-3.8\Release\src\python\grpcio
    creating python_build\temp.win32-3.8\Release\src\python\grpcio\grpc
    creating python_build\temp.win32-3.8\Release\src\python\grpcio\grpc\_cython
    creating python_build\temp.win32-3.8\Release\third_party
    creating python_build\temp.win32-3.8\Release\third_party\address_sorting
    creating python_build\temp.win32-3.8\Release\src\core
    creating python_build\temp.win32-3.8\Release\src\core\lib
    creating python_build\temp.win32-3.8\Release\src\core\lib\gpr
    creating python_build\temp.win32-3.8\Release\src\core\lib\gprpp
    creating python_build\temp.win32-3.8\Release\src\core\lib\profiling
    creating python_build\temp.win32-3.8\Release\src\core\lib\surface
    creating python_build\temp.win32-3.8\Release\src\core\lib\avl
    creating python_build\temp.win32-3.8\Release\src\core\lib\backoff
    creating python_build\temp.win32-3.8\Release\src\core\lib\channel
    creating python_build\temp.win32-3.8\Release\src\core\lib\compression
    creating python_build\temp.win32-3.8\Release\src\core\lib\debug
    creating python_build\temp.win32-3.8\Release\src\core\lib\http
    creating python_build\temp.win32-3.8\Release\src\core\lib\iomgr
    creating python_build\temp.win32-3.8\Release\src\core\lib\json
    creating python_build\temp.win32-3.8\Release\src\core\lib\slice
    creating python_build\temp.win32-3.8\Release\src\core\lib\transport
    creating python_build\temp.win32-3.8\Release\src\core\ext
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\server
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\server\secure
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\transport
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\alpn
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\http
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\http\client
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\http\message_compress
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\http\server
    creating python_build\temp.win32-3.8\Release\src\core\lib\security
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\context
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\alts
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\composite
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\fake
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\google_default
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\iam
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\jwt
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\local
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\oauth2
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\plugin
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\credentials\ssl
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\security_connector
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\transport
    creating python_build\temp.win32-3.8\Release\src\core\lib\security\util
    creating python_build\temp.win32-3.8\Release\src\core\tsi
    creating python_build\temp.win32-3.8\Release\src\core\tsi\alts
    creating python_build\temp.win32-3.8\Release\src\core\tsi\alts\crypt
    creating python_build\temp.win32-3.8\Release\src\core\tsi\alts\frame_protector
    creating python_build\temp.win32-3.8\Release\src\core\tsi\alts\handshaker
    creating python_build\temp.win32-3.8\Release\src\core\tsi\alts\zero_copy_frame_protector
    creating python_build\temp.win32-3.8\Release\third_party\nanopb
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\client
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\client\insecure
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\deadline
    creating python_build\temp.win32-3.8\Release\src\core\tsi\ssl
    creating python_build\temp.win32-3.8\Release\src\core\tsi\ssl\session_cache
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\client\secure
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\chttp2\server\insecure
    creating python_build\temp.win32-3.8\Release\src\core\ext\transport\inproc
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb\proto
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb\proto\grpc
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb\proto\grpc\lb
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb\proto\grpc\lb\v1
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb\proto\grpc\lb\v1\google
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\grpclb\proto\grpc\lb\v1\google\protobuf
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\resolver
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\resolver\fake
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\pick_first
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\lb_policy\round_robin
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\resolver\dns
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\resolver\dns\c_ares
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\resolver\dns\native
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\client_channel\resolver\sockaddr
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\census
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\max_age
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\message_size
    creating python_build\temp.win32-3.8\Release\src\core\ext\filters\workarounds
    creating python_build\temp.win32-3.8\Release\src\core\plugin_registry
    creating python_build\temp.win32-3.8\Release\src\boringssl
    creating python_build\temp.win32-3.8\Release\third_party\boringssl
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\asn1
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\base64
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\bio
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\bn_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\buf
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\bytestring
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\chacha
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\cipher_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\cmac
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\conf
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\curve25519
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\dh
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\digest_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\dsa
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\ec_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\ecdh
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\ecdsa_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\engine
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\err
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\evp
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\fipsmodule
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\hkdf
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\lhash
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\obj
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\pem
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\pkcs7
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\pkcs8
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\poly1305
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\pool
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\rand_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\rc4
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\rsa_extra
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\stack
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\x509
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\crypto\x509v3
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\ssl
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\third_party
    creating python_build\temp.win32-3.8\Release\third_party\boringssl\third_party\fiat
    creating python_build\temp.win32-3.8\Release\third_party\zlib
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DOPENSSL_NO_ASM=1 -D_WIN32_WINNT=1536 -DGPR_BACKWARDS_COMPATIBILITY_MODE=1 -DWIN32_LEAN_AND_MEAN=1 -DCARES_STATICLI
B=1 -DGRPC_ARES=0 -DNTDDI_VERSION=100663296 -DNOMINMAX=1 -DNTDDI_VERSION=100663296 -Isrc\python\grpcio -Iinclude -I. -Ithird_party\boringssl\include -Ithird_party\zlib -Ithird_party\nanopb -Ithird_party\cares -Ithird_party\cares\cares -Ithird_party\address_sorting\inc
lude -IC:\Users\Michael\Projects\GraknWorkbench\venv\include -IC:\Users\Michael\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\Michael\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\
Tools\MSVC\14.24.28314\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Window
s Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /EHsc /Tpsrc\python\grpcio\grpc/_cython/cygrpc.cpp /Fopython_build\temp.win32-3.8\Release\
src\python\grpcio\grpc/_cython/cygrpc.obj -std=c++11 -DPB_FIELD_16BIT
    cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
    cygrpc.cpp
    src\python\grpcio\grpc/_cython/cygrpc.cpp(1365): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory
    creating Users
    creating Users\Michael
    creating Users\Michael\AppData
    creating Users\Michael\AppData\Local
    creating Users\Michael\AppData\Local\Temp
    creating Users\Michael\AppData\Local\Temp\tmp5i1gp4i9
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\Michael\Projects\GraknWorkbench\venv\include -IC:\Users\Michael\AppData\Local\Programs\Python\Python38-32
\include -IC:\Users\Michael\AppData\Local\Programs\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)
\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Fi
les (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /TcC:\Users\Michael\AppData\Local\Temp\tmp5i1gp4i9\a.c /FoUsers\Michael\AppData\Local\Temp\tmp5i1gp4i9\a.obj
    a.c
    Traceback (most recent call last):
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\_msvccompiler.py", line 438, in compile
        self.spawn(args)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\_msvccompiler.py", line 557, in spawn
        return super().spawn(cmd)
      File "C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\src\python\grpcio\_spawn_patch.py", line 54, in _commandfile_spawn
        _classic_spawn(self, command)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\ccompiler.py", line 910, in spawn
        spawn(cmd, dry_run=self.dry_run)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\spawn.py", line 38, in spawn
        _spawn_nt(cmd, search_path, dry_run=dry_run)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\spawn.py", line 80, in _spawn_nt
        raise DistutilsExecError(
    distutils.errors.DistutilsExecError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\src\python\grpcio\commands.py", line 301, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 449, in build_extensions
        self._build_extensions_serial()
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial
        self.build_extension(ext)
      File "C:\Users\Michael\Projects\GraknWorkbench\venv\lib\site-packages\setuptools-40.8.0-py3.8.egg\setuptools\command\build_ext.py", line 199, in build_extension
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 528, in build_extension
        objects = self.compiler.compile(sources,
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\_msvccompiler.py", line 440, in compile
        raise CompileError(msg)
    distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\setup.py", line 332, in <module>
        setuptools.setup(
      File "C:\Users\Michael\Projects\GraknWorkbench\venv\lib\site-packages\setuptools-40.8.0-py3.8.egg\setuptools\__init__.py", line 145, in setup
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Michael\Projects\GraknWorkbench\venv\lib\site-packages\setuptools-40.8.0-py3.8.egg\setuptools\command\install.py", line 61, in run
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Michael\Projects\GraknWorkbench\venv\lib\site-packages\setuptools-40.8.0-py3.8.egg\setuptools\command\build_ext.py", line 78, in run
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 340, in run
        self.build_extensions()
      File "C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\src\python\grpcio\commands.py", line 305, in build_extensions
        raise CommandError(
    commands.CommandError: Failed `build_ext` step:
    Traceback (most recent call last):
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\_msvccompiler.py", line 438, in compile
        self.spawn(args)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\_msvccompiler.py", line 557, in spawn
        return super().spawn(cmd)
      File "C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\src\python\grpcio\_spawn_patch.py", line 54, in _commandfile_spawn
        _classic_spawn(self, command)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\ccompiler.py", line 910, in spawn
        spawn(cmd, dry_run=self.dry_run)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\spawn.py", line 38, in spawn
        _spawn_nt(cmd, search_path, dry_run=dry_run)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\spawn.py", line 80, in _spawn_nt
        raise DistutilsExecError(
    distutils.errors.DistutilsExecError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\src\python\grpcio\commands.py", line 301, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 449, in build_extensions
        self._build_extensions_serial()
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial
        self.build_extension(ext)
      File "C:\Users\Michael\Projects\GraknWorkbench\venv\lib\site-packages\setuptools-40.8.0-py3.8.egg\setuptools\command\build_ext.py", line 199, in build_extension
        _build_ext.build_extension(self, ext)
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build_ext.py", line 528, in build_extension
        objects = self.compiler.compile(sources,
      File "C:\Users\Michael\AppData\Local\Programs\Python\Python38-32\lib\distutils\_msvccompiler.py", line 440, in compile
        raise CompileError(msg)
    distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2


    ----------------------------------------
Command "C:\Users\Michael\Projects\GraknWorkbench\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Michael\\AppData\\Local\\Temp\\pip-install-xguw__my\\grpcio\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('
\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Michael\AppData\Local\Temp\pip-record-86jkdfzm\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\Michael\Projects\GraknWorkbench\venv\incl
ude\site\python3.8\grpcio" failed with error code 1 in C:\Users\Michael\AppData\Local\Temp\pip-install-xguw__my\grpcio\

Additional information

Installs on Linux fine. Looks like maybe an issue with gRPC? Not sure. Need assistance. In middle of project. Thanks so much! Seems like it starts to fail at: (see above)

    cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
    cygrpc.cpp
    src\python\grpcio\grpc/_cython/cygrpc.cpp(1365): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory

Python async/await support

Problem to Solve

Asynchronicity is not explicit.

Proposed Solution

We should consider use of the asyncio library to enable an async/await syntax, much like what is used in Client NodeJS.

However, I'm currently 50/50 on this idea. While we do use async/await in client-nodejs, and it works well for highlighting remote calls that need to be awaited, as well as allowing people to execute remote calls in the background, it isn't exactly... pretty, at least in the Concept API when chaining multiple Concept API calls. Moreover, we don't have it in client-java.

But it may be nicer to use for users. We already had one request to support async and await.

Ideally, we should consult with experienced Python users to help make a call on this. We should also check if adding asyncio breaks compatibility with existing code, or if it can be integrated seamlessly - since, probably, not everyone wants to be writing async and await everywhere when they use typedb-client.

read an complete .gql file | insert behaviour

Problem to Solve

If you have an .gql file, that contains definitions and inserts then this causes an exception

with open("/path/grakn/grakn-core-all-linux-1.5.0/tests/foo.gpl") as f:
    definitions_and_inserts = f.read()

with GraknClient(uri="localhost:48555") as client:
    with client.session(keyspace="test") as session:
        with session.transaction().write() as write_transaction:
            write_transaction.query(definitions_and_inserts)
            write_transaction.commit() 

but from console this works:

./grakn console --keyspace test --file tests/foo.gql

Current Workaround

To avoid such behavior the original .gql file need to be split in two parts, definitions as one and inserts as the other like this:

with open("/path/grakn/grakn-core-all-linux-1.5.0/tests/foo_d.gpl") as f:
    definitions = f.read()

with open("/path/grakn/grakn-core-all-linux-1.5.0/tests/foo_i.gpl") as f:
    inserts = f.read()

with GraknClient(uri="localhost:48555") as client:
    with client.session(keyspace="test") as session:
        with session.transaction().write() as write_transaction:
            write_transaction.query(definitions)  
            write_transaction.query(insert)
            write_transaction.commit()

Now the definitions are committable, but unfortunately the insert part still fails with exceptions.

So one needs to do the following:

with open("/path/grakn/grakn-core-all-linux-1.5.0/tests/foo_i.gpl") as f:
    inserts = [e for e in f.read().split("\n\n") if e.strip() and not e.startswith("#")] 
    # Attention see below

with GraknClient(uri="localhost:48555") as client:
    with client.session(keyspace="test") as session:
        with session.transaction().write() as write_transaction:
            write_transaction.query(definitions)  
            for insert in inserts:
                write_transaction.query(insert)
            write_transaction.commit()

But since in the foo_i.gql some of the inserts are multilines (match\n..\n..insert\n..\n) one need to insert blank lines to make an easy split with little logic (not empty and not just a comment which also causes exceptions) and split at \n\n. This is painful since one needs to also split up single-line inserts with blank lines.

Example:

insert $n isa NNP, has Lemma "Geldstrafe";

insert $z isa NZP, has Lemma "Jahre", has Eigenschaft "bis zu fünf (<=5)";

match 
    $NO isa NEP, has Lemma "Wer";
    $DO isa NEP, has Lemma "anderer";
    $AO isa NNP, has Lemma "Sache";
    $PO isa NNP, has Lemma "in der Absicht";
insert
    $VP (NO: $NO, DO: $DO, AO: $AO, PO: $PO) isa VP;
    $VP has Lemma "wegnehmen";

match 
    $A1 isa NEP, has Lemma "Wer";
    $A2 isa NEP, has Lemma "Dritter";
insert
    $Alt (Alt_1: $A1, Alt_2: $A2) isa Alternative;
    $Alt has Lemma "oder";

(the blank line between the first two inserts is painful especially if you have a lot of them).

Proposed Solution

Since my guess is that you don't want to change the behaviour of write_transaction.query() it be great to have a write_transaction.from_file() which would take the path to the original foo.gql and read it without exceptions like:

with GraknClient(uri="localhost:48555") as client:
    with client.session(keyspace="test") as session:
        with session.transaction().write() as write_transaction:
            write_transaction.from_file("/path/grakn/grakn-core-all-linux-1.5.0/tests/foo.gpl")
            write_transaction.commit()

Incompatibility with Python >=3.8 caused by grpcio 1.24

Description

grpcio fails to build using bazel build //... on Python 3.8. The C compiler throws multiple unresolvable errors.

The issue can be resolved by upgrading grpcio to 1.33.1.

Given that this upgrade is desirable anyway, we should get on with it.

Environment

  1. OS (where Grakn server runs): Mac OS 11
  2. Grakn version (and platform): Grakn Core 1.8
  3. Grakn client-python version: client-python 1.8
  4. Python version: 3.8.5

Reproducible Steps

bazel build //...

Additional information

Blindly upgrading gRPC is not sensible - it causes an issue where all RPC requests fail in Grakn. However, we can resolve this by also upgrading Netty to 4.1.51.

get() function in the python client to filter the concepts associated with a specific variable

Problem to Solve

Suppose we want to get the values of all the attributes of a certain EntityType. Based on this page https://dev.grakn.ai/docs/client-api/python I have two ways to execute a read transaction and reach my goal.
First approach:

Second approach:

Using the latter approach I noticed benefits in terms of performance when as a query I have a rule as discussed here vaticle/typedb#5227. However, the disadvantage is that I must specify the label (product in this case) of the EntityType of interest, while with the first approach I can always use the same variable x and formulate the query by associating the variable x with the EntityType of interest.

Proposed Solution

For this reason it would be useful to implement a get method similar to the following

read_transaction.concepts().get_thing_type() raises AttributeError: 'ConceptManager' object has no attribute 'get_thing_type'

Description

When calling read_transaction.concepts().get_thing_type("relation") I get

Traceback (most recent call last):
File "", line 1, in
AttributeError: 'ConceptManager' object has no attribute 'get_thing_type'

Environment

  1. OS (where Grakn server runs): Mac OS 10.14.6
  2. Grakn version (and platform): Grakn Core 2.0.0-alpha-3
  3. Grakn client-python version: client-python 2.0.0a5
  4. Python version: 3.9

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Open a python terminal
  2. from grakn.client import *
  3. client = GraknClient("127.0.0.1:1729")
  4. session = client.session(<myschema>, SessionType.SCHEMA)
  5. tx = session.transaction(TransactionType.READ)
  6. tx.concepts().get_thing_type("relation")

Expected Output

a type object

Actual Output

Traceback (most recent call last):
File "", line 1, in
AttributeError: 'ConceptManager' object has no attribute 'get_thing_type'

Python client leaks threads on failed queries

Description

When using the Python client to do bulk inserts, I've found that the client is leaking threads (enough that it inevitably crashes the client when the dataset is large enough, i.e. more than a few hundred records). I believe this has to do something with the way I was inserting, which was to catch exceptions when I was adding an entity that had already been added before; due to the way the data I've been given is structured, I was content to eat the cost of discarding duplicate inserts by catching exceptions, but it blows up every time I try it.

Environment

  1. OS (where Grakn server runs): OS X 10.14.5
  2. Grakn version (and platform): Grakn Core 1.5.7
  3. Grakn client-python version: client-python 1.5.3
  4. Python version: 3.7.4

Reproducible Steps

This is the inner loop of the code I'm writing (based off of the python phone_calls example):


    with GraknClient(uri=f"{host}:{port}") as client:
        for section_name in config.csv_inputs:
            section = config.csv_inputs[section_name]
            path = os.path.join(data_dir,section.file)
            with client.session(keyspace=config.grakn.keyspace) as session:
                items = parse_data_to_dictionaries(path)

                for item in items:
                    # This is the same structure as the example, funcs returning query strings; 
                    # I'm just returning a list instead of a single query because I have a more 
                    # complex data structure.
                    graql_insert_queries = templates[section.template](item,section)

                    for query in graql_insert_queries:
                        with session.transaction().write() as transaction:                            
                            try:
                                transaction.query(query)
                                transaction.commit()
                            except GraknError as e:
                                print(f"Query failed: {e}")

I track the threads using ps M <pid> | wc -l. When the queries are not failing the thread count remains steady at the same number of threads as cores; after a few hundred/thousand failed queries, the thread count balloons into the thousands and the python client gives up with cannot create new thread.

Output

This is the error that gets thrown when it runs out of threads:

Traceback (most recent call last):
  File "cli.py", line 64, in <module>
    data_loader()
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "cli.py", line 51, in data_loader
    with session.transaction().write() as transaction:                            
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/grakn/client.py", line 106, in write
    transaction_service = TransactionService(self._session_id, _TxType.WRITE, self._transaction_rpc_constructor)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 35, in __init__
    self._communicator = Communicator(transaction_endpoint)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 133, in __init__
    self._response_iterator = grpc_stream_constructor(self)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/grpc/_channel.py", line 683, in __call__
    self._request_serializer, event_handler)
  File "/Users/XXX/Envs/XXX/lib/python3.7/site-packages/grpc/_channel.py", line 248, in _consume_request_iterator
    consumption_thread.start()
  File "src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi", line 107, in grpc._cython.cygrpc.ForkManagedThread.start
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 852, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

Session pulse producing too many threads

Description

Currently, each session pulse is sent in a separate thread; a few minutes of keeping session open shows the thread number grow:

In [60]: threading.enumerate()
Out[60]: 
[<_MainThread(MainThread, started 140324098783040)>,
 <HistorySavingThread(IPythonHistorySavingThread, started 140324065166912)>,
 <Thread(Thread-293, started daemon 140323535701568)>,
 <Thread(Thread-294, started daemon 140323552486976)>]

Refactor proposals:

  • instead of creating new threads over and over, use concurrent.futures.ThreadPoolExecutor which creates new threads on demand (but keeps some alive and doesn't create excess of them)
  • Name it accordingly, including the session name such that it's easy to differentiate them:
In [1]: from concurrent.futures import ThreadPoolExecutor
In [2]: ex = ThreadPoolExecutor(thread_name_prefix='session_pulse_6688ccd6278d4b959a499f4cb2e49ffb')
In [3]: threading.enumerate()
Out[3]: 
[<_MainThread(MainThread, started 139758585063232)>,
 <HistorySavingThread(IPythonHistorySavingThread, started 139758551447104)>,
 <Thread(session_pulse_6688ccd6278d4b959a499f4cb2e49ffb_0, started daemon 139758437135936)>]

`pypi_dependencies` and `pypi_deployment_dependencies` to be direct dependencies

At the moment pypi_dependencies and pypi_deployment_dependencies are pulled in from Grakn Core, where they've recently been removed and are not available anymore. In fact, if client-python depends on the latest commit of Grakn master, bazel build //... would break.

These two dependencies need to be defined as the direct dependencies of client-python.

Update //:test_integration to work with RBE

//:test-integration doesn't yet work with RBE. Follow the approach done by @graknlabs_grakn//test-end-to-end/client-java:client-java-e2e in order to make it work:

  • The test needs to depend on //:distribution so it knows to re-run the test when the distribution is changed in any way.
  • Grakn needs to be started and stopped from within the test as opposed to from circleci

Once the test has been made to work with RBE, change the circleci yml such that //n:test-integration is executed using the RBE mode:

bazel:
  command: bazel ...

Remove dependency on six

Description

six is a package that provides import statements compatible with both Python 2 and 3. Given we no longer support Python 2 (and in fact use some Python 3-specific language features, such as type hints), we should get rid of six dependency and replace all imports with their respective Python 3 equivalents.

deploy-github fails because of python compatibility errors

There are two errors:

ci:release-notes error (https://circleci.com/gh/graknlabs/client-python/2166)
ci:release-notes would fail when pyenv global is set to 2.7.123.5.2. If we remove the pyenv call, it will work

pyenv global 2.7.12 3.5.2
pip install certifi
export RELEASE_NOTES_TOKEN=$REPO_GITHUB_TOKEN
bazel run @graknlabs_build_tools//ci:release-notes -- client-python $(cat VERSION) ./RELEASE_TEMPLATE.md

...
Traceback (most recent call last):
  File "/home/********/.cache/bazel/_bazel_********/a3bf690c4bacc2f8a31e33bc35f6090b/execroot/graknlabs_client_python/bazel-out/k8-fastbuild/bin/external/graknlabs_build_tools/ci/release-notes.runfiles/graknlabs_build_tools/ci/release-notes.py", line 3, in <module>
    import github
  File "/home/********/.cache/bazel/_bazel_********/a3bf690c4bacc2f8a31e33bc35f6090b/execroot/graknlabs_client_python/bazel-out/k8-fastbuild/bin/external/graknlabs_build_tools/ci/release-notes.runfiles/pypi__PyGithub_1_43_2/github/__init__.py", line 42, in <module>
    from github.MainClass import Github, GithubIntegration
  File "/home/********/.cache/bazel/_bazel_********/a3bf690c4bacc2f8a31e33bc35f6090b/execroot/graknlabs_client_python/bazel-out/k8-fastbuild/bin/external/graknlabs_build_tools/ci/release-notes.runfiles/pypi__PyGithub_1_43_2/github/MainClass.py", line 53, in <module>
    from httplib import HTTPSConnection
ImportError: No module named 'httplib'

deploy-github error (https://circleci.com/gh/graknlabs/client-python/2168)
deploy-github would fail if pyenv global is set to 2.7.123.5.2. I did not try testing invoking deploy-github without setting pyenv, so I didn't know if it'll work without the pyenv call.

pyenv global 2.7.12 3.5.2
export DEPLOY_GITHUB_TOKEN=$REPO_GITHUB_TOKEN
bazel run --define version=$(cat VERSION) //:deploy-github -- $CIRCLE_SHA1

...
Could not find pip-provided dependency: 'enum34'
ERROR: Skipping '//:deploy-github': no such target '//:deploy-github': target 'deploy-github' not declared in package '' defined by /home/********/client-python/BUILD

Upgrade to Grakn 2.0

Our Python client needs to be upgraded to interact with Grakn 2.0. This is a major overhaul that heavily impacts the entire codebase.

The main goals are:

  • alignment of structure and implementation with client-java
  • compatibility with Grakn 2.0

Client-side timeout

Client-python does not set a client-side timeout, and will stall forever if the network gets interrupted

Grakn version:
1.5

Reproducible step:

  1. Start grakn: grakn server start
  2. Run the python-equivalent of the following Java queries using client-python:
try (GraknClient.Session session = new GraknClient("localhost:48555").session("grakn")) {
        while (true) {
                GraknClient.Transaction tx = session.transaction(Transaction.Type.WRITE);
                tx.execute(Graql.match(var("x").sub("thing")).get());
                System.out.println("query");
                tx.commit();
        }
}
  1. Pause grakn in the middle: kill -STOP <grakn process id>
  2. Observe that the queries will stall and never times out

TODO

  1. The client should be able to set a timeout when instantiating the client. We need to set a default, eg., 15 seconds.
client1 = new Grakn(DEFAULT_URI, 20) // timeout set to 20 seconds
client2 = new Grakn(DEFAULT_URI) // timeout set to the default timeout, eg., 15 seconds
  1. The provided timeout value should be used to set the deadline of GRPC requests.

TypeError: Couldn't build proto file into descriptor pool!

Description

I installed grakn-client but I am getting the following error when I try to run from grakn.client import GraknClient:

TypeError: Couldn't build proto file into descriptor pool!

Environment

  1. OS (where Grakn server runs): Mac 10.14.6
  2. Grakn version (and platform): 1.6.2
  3. Grakn client-python version: 1.6.0
  4. Python version: 3.6.7
  5. Other environment details:

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Ran pip install grakn-client from terminal. Installed successfully.
  2. Ran from grakn.client import GraknClient from Jupyter Notebook

Expected Output

I expected the module to load without issues.

Actual Output

I received the following error:
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
----> 1 from grakn.client import GraknClient

~/anaconda/lib/python3.6/site-packages/grakn/client.py in
7 from grakn.service.Keyspace.KeyspaceService import KeyspaceService
8 from grakn.service.Session.TransactionService import TransactionService
----> 9 from grakn_protocol.session.Session_pb2_grpc import SessionServiceStub
10 from grakn.exception.GraknError import GraknError
11

~/anaconda/lib/python3.6/site-packages/grakn_protocol/session/Session_pb2_grpc.py in
2 import grpc
3
----> 4 from grakn_protocol.session import Session_pb2 as session_dot_Session__pb2
5
6

~/anaconda/lib/python3.6/site-packages/grakn_protocol/session/Session_pb2.py in
13
14
---> 15 from grakn_protocol.session import Concept_pb2 as session_dot_Concept__pb2
16 from grakn_protocol.session import Answer_pb2 as session_dot_Answer__pb2
17

Detect incompatibility and raise a relevant exception

Problem to Solve

When there is an incompatibility between Client Python and the running Grakn Server, the exception thrown by the client seems unrelated to the real cause of the problem. In fact, the error message may even be incorrect, given that the keyspace does exist with the given name.

Current Workaround

If encountering this exception for the first time, only searching the web or asking the community can lead the user to the solution.

Proposed Solution

Have Client Python to identify the incompatibility and throw an exception with a helpful message. e.g. Client Python version 1.5.3 does not support the running Grakn Core server. Please refer to the documentation of client Python to ensure compatibility.

Additional Information

N/A

Make Client Python able to run our BDD scenarios

Problem to Solve

Our client-python E2E tests do not cover all the cases that Grakn clients are required to support. There is a high chance that there are still bugs present that have not been caught by our existing tests.

Current Workaround

N/A

Proposed Solution

Make Client Python able to run our BDD scenarios.

Server/network error on creating a new transaction

Grakn version: 1.5 SNAPSHOT (c80b4d644aec10895171c2083ed0378b506b01f0)
Client version: 1.5 SNAPSHOT (http://repo.grakn.ai/repository/test-pypi-group/packages/grakn-client/1.5.0-252e5170fb3b13a0c08f7b9c5de59cb2b0a15ef4/grakn-client-1.5.0-252e5170fb3b13a0c08f7b9c5de59cb2b0a15ef4.tar.gz)

import grakn

client = grakn.Grakn(uri="localhost:48555")
with client.session(keyspace="test") as session:
    with session.transaction(grakn.TxType.READ) as transaction:
        print(client, session, transaction)

Expected outcome:

see the correct result of the print statement.

Actual outcome

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 145, in send
    response = next(self._response_iterator)
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 363, in __next__
    return self._next()
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 357, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "null. Please check server logs for the stack trace."
	debug_error_string = "{"created":"@1551193247.463363000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1036,"grpc_message":"null. Please check server logs for the stack trace.","grpc_status":2}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    with session.transaction(grakn.TxType.READ) as transaction:
  File "/usr/local/lib/python3.7/site-packages/grakn/__init__.py", line 74, in transaction
    transaction_service = TransactionService(self.keyspace, tx_type, self.credentials, self._stub.transaction)
  File "/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 39, in __init__
    self._communicator.send(open_req)
  File "/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py", line 149, in send
    raise ClientError("Server/network error: {0}\n\n generated from request: {1}".format(e, request))
grakn.exception.ClientError.ClientError: Server/network error: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "null. Please check server logs for the stack trace."
	debug_error_string = "{"created":"@1551193247.463363000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1036,"grpc_message":"null. Please check server logs for the stack trace.","grpc_status":2}"
>

 generated from request: open_req {
  keyspace: "test"
}
2019-02-26 15:00:47,454 [grpc-default-executor-0] ERROR g.c.s.r.SessionService$TransactionListener - Runtime Exception in RPC TransactionListener:
java.lang.NullPointerException: null
	at grakn.core.server.rpc.SessionService$TransactionListener.open(SessionService.java:271)
	at grakn.core.server.rpc.SessionService$TransactionListener.handleRequest(SessionService.java:191)
	at grakn.core.server.rpc.SessionService$TransactionListener.lambda$onNext$1(SessionService.java:159)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

python client data read issue

Hello,

In my local machine (python 3.8.2 on macos big sur ), I am experimenting with grakn server 2.0.0-alpha-8 with python client grakn-client==2.0.0a10.

Using the Grakn console, I am able to do create-delete databases, load schemas, insert data, and read it,
However, in python client I am having serious issues with reading data from the database.
I have a very simple db called 'grakn' where i inserted 6 lion entities (it was an example in the documentation)

With the code below I successfully get a map object,


from grakn.client import GraknClient, SessionType, TransactionType

q='match $x isa lion; get $x;'

with GraknClient.core("localhost:1729") as client:

    with client.session("grakn", SessionType.DATA) as session:

        with session.transaction(TransactionType.READ) as tx:

            answer_iterator = tx.query().match(q)

            print(answer_iterator)

When I want to access fields of it either via iteration as "for x in aswer_iterator etc" or via trying to convert it to a list "list(answer_iterator)" as shown in the examples in the documentation of the client, i get the following error:
GraknClientException: The encoding 0 was not recognised.

Any idea how I can troubleshoot the issue?
Thanks

client.databases().delete(<database>) raises AttributeError: '_DatabaseManagerRPC' object has no attribute 'delete'

Description

calling client.databases().delete(<database>) raises AttributeError:

'_DatabaseManagerRPC' object has no attribute 'delete'

Environment

  1. OS (where Grakn server runs): Mac OS 10
  2. Grakn version (and platform): Grakn Core 2.0.0-alpha-8
  3. Grakn client-python version: client-python 2.0.0-alpha-8
  4. Python version: 3.8.5

Reproducible Steps

Steps to create the smallest reproducible scenario:
Open a Python REPL, then

  1. from grakn.client import *
  2. client = GraknClient.core("localhost:1729")
  3. client.databases().create(“test”)
  4. client.databases().delete("test”)

Expected Output

silent deletion of "test" database

Actual Output

Traceback (most recent call last):
File "", line 1, in
AttributeError: '_DatabaseManagerRPC' object has no attribute 'delete'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.