Skip to main content

Memgraph database adapter for Python language

Project description

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.

Prerequisites

Build prerequisites

pymgclient is a C wrapper around the mgclient Memgraph client library. To install it from sources you will need:

  • Python 3.5 or newer
  • A C compiler supporting C11 standard
  • Python header files
  • mgclient header files

Once prerequisites are met, you can install pymgclient using pip to download it from PyPI:

$ pip3 install pymgclient

or using setup.py if you have downloaded the source package locally:

$ python3 setup.py build
$ python3 setup.py install

Runtime requirements

mgclient Python module requires mgclient shared library at runtime (usually distributed as libmgclient.so). The module relies on the host OS to find the location. If the library is installed in a standard location, there should be no problems. Otherwise, you will have to let the mgclient module how to find it (usually by setting the LD_LIBRARY_PATH environment variable).

You will also need OpenSSL libraries required by the mgclient C library.

Running the test suite

Once mgclient is installed, you can run the test suite to verify it is working correctly. From the source directory, you can run:

$ python3 -m pytest

To run the tests, you will need to have Memgraph, pytest and pyopenssl installed on your machine. The tests will try to start the Memgraph binary from the standard installation path (usually /usr/lib/memgraph/memgraph) listening on port 7687. You can configure a different path or port by setting the following environment variables:

  • MEMGRAPH_PATH
  • MEMGRAPH_PORT

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymgclient-0.1.0.tar.gz (30.7 kB view details)

Uploaded Source

File details

Details for the file pymgclient-0.1.0.tar.gz.

File metadata

  • Download URL: pymgclient-0.1.0.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.3

File hashes

Hashes for pymgclient-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b881252d76c82329421a19bc3140016fb4bf4ce13740b68eae98e53c4598535e
MD5 e93b1950ad0fd9c88c53e39ec55d4de5
BLAKE2b-256 a0062ae8f4e4c77513ff90055814b479473a5e3bf75ceb4cd68ed554567bf297

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page