GithubHelp home page GithubHelp logo

memgraph / pymgclient Goto Github PK

View Code? Open in Web Editor NEW
43.0 9.0 5.0 463 KB

Python Memgraph Client

Home Page: https://memgraph.github.io/pymgclient/

License: Apache License 2.0

Python 36.82% C 63.18%
memgraph python database-adapter python-programming-language client

pymgclient's Introduction

Actions Status

pymgclient - Memgraph database adapter for Python language

pymgclient is a Memgraph database adapter for Python programming language compliant with the DB-API 2.0 specification described by PEP 249.

mgclient module is the current implementation of the adapter. It is implemented in C as a wrapper around mgclient, the official Memgraph client library. As a C extension, it is only compatible with the CPython implementation of the Python programming language.

pymgclient only works with Python 3.

Check out the documentation if you need help with installation or if you want to build pymgclient for yourself!

Documentation

Online documentation can be found on GitHub pages.

You can also build a local version of the documentation by running make from the docs directory. You will need Sphinx installed in order to do that.

Code sample

Here is an example of an interactive session showing some of the basic commands:

>>> import mgclient

# Make a connection to the database
>>> conn = mgclient.connect(host='127.0.0.1', port=7687)

# Create a cursor for query execution
>>> cursor = conn.cursor()

# Execute a query
>>> cursor.execute("""
        CREATE (n:Person {name: 'John'})-[e:KNOWS]->
               (m:Person {name: 'Steve'})
        RETURN n, e, m
    """)

# Fetch one row of query results
>>> row = cursor.fetchone()

>>> print(row[0])
(:Person {'name': 'John'})

>>> print(row[1])
[:KNOWS]

>>> print(row[2])
(:Person {'name': 'Steve'})

# Make database changes persistent
>>> conn.commit()

pymgclient's People

Contributors

antaljanosbenjamin avatar gitbuda avatar jbajic avatar kostasrim avatar marioherceg avatar mferencevic avatar tomicm 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pymgclient's Issues

MgClient installation Error in PYMgClient

Hi

I want to install pymgclient and I run into problem with mgclient. So I installed mgclient seperate and it worked. How can I change the setup.py to use the installed mgclient library to avoid the error in the installation process?

`(memgraph) [anton@comp pymgclient]$ pip install --user pymgclient
Collecting pymgclient
Using cached pymgclient-1.3.1.tar.gz (125 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: pymgclient
Building wheel for pymgclient (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [50 lines of output]
running bdist_wheel
running build
running build_ext
Using static OpenSSL: True
Checking if cmake3 can be used
Using /usr/bin/cmake3
Preparing the build environment for mgclient
Using /tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_build as build directory for mgclient
Using /tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_install as install directory for mgclient
Configuring mgclient
/usr/bin/cmake3 /tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/mgclient -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_INCLUDEDIR=include -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_install -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON "-DCMAKE_C_FLAGS="-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/anton/mambaforge/envs/memgraph/include -Werror=all"" -DOPENSSL_USE_STATIC_LIBS=ON
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /home/anton/mambaforge/envs/memgraph/bin/x86_64-conda-linux-gnu-cc
-- Check for working C compiler: /home/anton/mambaforge/envs/memgraph/bin/x86_64-conda-linux-gnu-cc - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler

      "/home/anton/mambaforge/envs/memgraph/bin/x86_64-conda-linux-gnu-cc"
  
    is not able to compile a simple test program.
  
    It fails with the following output:
  
      Change Dir: '/tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_build/CMakeFiles/CMakeScratch/TryCompile-Z7EYZO'
  
      Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_714f2/fast
      /usr/bin/gmake  -f CMakeFiles/cmTC_714f2.dir/build.make CMakeFiles/cmTC_714f2.dir/build
      gmake[1]: Verzeichnis „/tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_build/CMakeFiles/CMakeScratch/TryCompile-Z7EYZO“ wird betreten
      Building C object CMakeFiles/cmTC_714f2.dir/testCCompiler.c.o
      /home/anton/mambaforge/envs/memgraph/bin/x86_64-conda-linux-gnu-cc   "-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/anton/mambaforge/envs/memgraph/include -Werror=all"  -fPIE -o CMakeFiles/cmTC_714f2.dir/testCCompiler.c.o -c /tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_build/CMakeFiles/CMakeScratch/TryCompile-Z7EYZO/testCCompiler.c
      cc1: error: bad value ('nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/anton/mambaforge/envs/memgraph/include -Werror=all') for '-march=' switch
      cc1: note: valid arguments to '-march=' switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client rocketlake icelake-server cascadelake tigerlake cooperlake sapphirerapids alderlake bonnell atom silvermont slm goldmont goldmont-plus tremont knl knm x86-64 x86-64-v2 x86-64-v3 x86-64-v4 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 znver3 btver1 btver2 native
      gmake[1]: *** [CMakeFiles/cmTC_714f2.dir/build.make:78: CMakeFiles/cmTC_714f2.dir/testCCompiler.c.o] Fehler 1
      gmake[1]: Verzeichnis „/tmp/pip-install-h0caef9e/pymgclient_c2d578c78849442690ef3f64202b7eb6/build/temp.linux-x86_64-cpython-39/mgclient_build/CMakeFiles/CMakeScratch/TryCompile-Z7EYZO“ wird verlassen
      gmake: *** [Makefile:127: cmTC_714f2/fast] Fehler 2
  
  
  
  
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:22 (project)
  
  
  -- Configuring incomplete, errors occurred!
  error: command '/usr/bin/cmake3' failed with exit code 1
  [end of output]

`

import mgclient error

ImportError: /data/anaconda3/envs/xss/lib/python3.10/site-packages/mgclient.cpython-310-x86_64-linux-gnu.so: undefined symbol: SSL_get1_peer_certificate

Issue with Ubuntu 22.04 duee to libssl-dev version

When using ubuntu 22.04 and installing gqlalchemy with python 3.10 I get the following error:

from gqlalchemy import memgraph
Traceback (most recent call last):
File "", line 1, in
File "/home/lewis/miniconda3/envs/gql/lib/python3.10/site-packages/gqlalchemy/init.py", line 34, in
from gqlalchemy.instance_runner import ( # noqa F401
File "/home/lewis/miniconda3/envs/gql/lib/python3.10/site-packages/gqlalchemy/instance_runner.py", line 31, in
from gqlalchemy.vendors.memgraph import Memgraph
File "/home/lewis/miniconda3/envs/gql/lib/python3.10/site-packages/gqlalchemy/vendors/memgraph.py", line 19, in
from gqlalchemy.connection import Connection, MemgraphConnection
File "/home/lewis/miniconda3/envs/gql/lib/python3.10/site-packages/gqlalchemy/connection.py", line 18, in
import mgclient
ImportError: /home/lewis/miniconda3/envs/gql/lib/python3.10/site-packages/mgclient.cpython-310-x86_64-linux-gnu.so: undefined symbol: SSL_get1_peer_certificate

Add pyproject.toml

Hoping that you guys can add support for pyproject.toml, since you only currently support setup.py install. This is deprecated in later pip versions and as of pip>=23.1 this behavior change is enforced or requires a --use-pep517 flag.

openssl 3.0.2

Hi there,

I am getting this issue after trying to compile pymgclient on Ubuntu 22.04. Could you help please? thanks

ImportError:miniconda3/envs/eth/lib/python3.10/site-packages/mgclient.cpython-310-x86_64-linux-gnu.so: undefined symbol: SSL_get1_peer_certificate

pymgclient build/import issue

I'm running memgraph-mage in a docker container and building pymgclient in another. The build process goes fine, but when I try to import pymgclient, I get an error that seems to have something to do with SSL, but I'm not quite sure.

import mgclient
ImportError: .../python3.9/site-packages/mgclient.cpython-39-x86_64-linux-gnu.so: undefined symbol: EVP_PKEY_base_id

Any ideas?

Request to release linux wheel for python 3.7

Hi,
I am trying to consume the library but however for some reason since the wheel for linux is not available , I am not able to add it through the dependency pipeline. Could you please release the linux wheel for python 3.7 ?

Thanks
Raghavendar S

Release the GIL when dealing with not Python related things

Without releasing the GIL while doing not Python related things (especially IO) using multiple threads can be inefficient. A possible workaround is using multiple processes, but then sharing data requires pickling/unpickling.

This issue is the result of a discussion on Memgraph's Discord server.

Installation instructions for Fedora 39

Hello, can you provide installation instructions for current Fedora versions?

Having adhered to prerequisites and current installation docs, environment setup via

dnf install python3.11-devel cmake3 make gcc gcc-c++ openssl1.1-devel
mkdir myproj
cd myproj
python3.11 -m venv venv
. venv/bin/activate
pip install pymgclient

leads to following error caused by cmake3:

  CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
   Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
   system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
   version "1.1.1q")
 Call Stack (most recent call first):
   /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
   /usr/share/cmake/Modules/FindOpenSSL.cmake:668 (find_package_handle_standard_args)
   src/CMakeLists.txt:50 (find_package)    
 -- Configuring incomplete, errors occurred!
 error: command '/usr/bin/cmake3' failed with exit code 1

I tried to set environment variables OPENSSL_ROOT_DIR and OPENSSL_CRYPTO_LIBRARY without success. Also note that OpenSSL 1.1 is intended to be removed starting with Fedora 40.

Possibly related: #53

Connection to host

Hi, I am trying to connect to the host as in the given example. However, I get the error below.
Could it be that the firewall is blocking it? Which programs need to be allowed to pass?

OperationalError Traceback (most recent call last)
Input In [10], in <cell line: 1>()
----> 1 conn = mgclient.connect(host='127.0.0.1', port=7687)

OperationalError: couldn't connect to host: Connection refused.

Blocking behavior of pymgclient

It appears that pymgclient's behavior is different from neo4j's library in a way that pymgclient blocks all operations of an app until the cypher query is completely performed. Would it be possible to use async withingn pymgclient (if neo4j uses async, as we suspect)?

Remove key quoting from string representation of node/edge

Hello!

I'm working on a knowledge graph application where our entities have messy names (i.e. obama and barack obama for instance). I'm working on giving the users a way to merge entities together into a single entity with all corresponding edges.

I'm relying on the string representations of nodes/edges to build the queries to do this, and I'm running into issues since the keys are quoted. For example:

( :PERSON { 'name': 'barack obama', 'class': 'Node' } )

rather than:

( :PERSON { name: 'barack obama', class: 'Node' } )

I implemented my own to_str function to handle this. I think this would be nice to fix, unless I'm completely missing something obvious! Thank you!

Maybe don't link openssl statically by default?

Problem

Linking openssl statically by default implies the image must have a static libcrypto.a, but not all *nixes ship that when installing openssl. In particular, RockyLinux 8 doesn't ship that, causing pip install pymgclient==1.3.1 to fail.

How was it discovered?

  1. pip install gqlachemy fails on a fresh Rockylinux 8 image with the build prerequisites installed. Error message suggests something's up with pymgclient and openssl's version.
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found version "3.0.8")
  1. Tried opting out of the static linking and the installation worked.
pip install pymgclient \
    --global-option="build_ext" \
    --global-option="--static-openssl=0"

Proposed fix

  • Keep the openssl static linking the default behaviour and add another CI job.

Add another base image, say rockylinux:8, to CI where libcrypto.a is not provided by openssl-devel or libssl-dev. Fix the rest of CI job until the build passes and possibly improve documentation on the build process.

The reason ubuntu-22.04 didn't surface this error is because libssl-dev ships a libcrypto.a by default and the Runner comes with an openssl installed.

OR

  • Remove the default static linking of openssl:
# setup.cfg
[build_ext]
static_openssl = 0

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.