Skip to main content

The official MillenniumDB driver for Python

Project description

MillenniumDB Driver


PyPI Latest Release PyPI downloads License

Here you can find the official Python driver for the MillenniumDB server.

Check out the driver for different languages!

Table of contents

  1. Directory structure
  2. Build instructions

1. Directory structure

📦millenniumdb_driver
├── 📂docs/ ---------------------------- Documentation generator (Sphinx)
├── 📂src/ ----------------------------- The Python implementation
├── 📜LICENSE
├── 📜README.md
├── 📜pyproject.toml
└── 📜setup.cfg

2. Build instructions

Setup

Dependencies:

  • Git
  • Setuptools
  • Wheel
  • A running MillenniumDB server instance

Installation

Install the driver and the dependecies.

pip install millenniumdb_driver

Usage

After successfully installing the project, you can start using the library in your Python programs.

Creating a Driver instance

First you must create a Driver instance:

import millenniumdb_driver

url = 'your-server-url' # e.g. ws://localhost:1234
driver = millenniumdb_driver.driver(url)

When you are done with the driver, you should close it before exiting the application.

driver.close()

Acquiring a Session

For sending queries to the MillenniumDB server, you must acquire a session instance:

session = driver.session()

Then you can send queries through your session.

query = 'MATCH (?from)-[:?type]->(?to) RETURN * LIMIT 10'
result = session.run(query)

Consuming results

The alternatives for consuming results must never be mixed because it would generate undefined behavior on your client and/or server. It is important to mention that the session must be closed when your operations are done.

result.variables() -> Tuple[str]

Returns the list of variables in the result.

result.records() -> List[Record]

Returns the list of Records in the result.

result.values() -> List[object]

Returns the list of values in the result.

result.data() -> List[Dict[str, object]]

Returns the list of records in the result as dictionaries.

result.to_df() -> "DataFrame"

Returns the result as a Pandas DataFrame.

result.summary() -> object

Returns the summary of the result.

for record in result: -> Iterator[Record]
    print(record)

Iterates over each record in result.

Parametric queries

To prevent injections, session.run() accepts a second argument: a dictionary that maps variables to values. This lets you create safe, parametric queries with preset bindings that are automatically sanitized by the database.

result = session.run(
    "MATCH (?person :Person)-[:owns]->(?car :Car) WHERE ?person.age > ?my_arg RETURN *",
    { "my_arg": 25 },
)

MillenniumDB types can be constructed from python to pass it as parametric values. This are available under millenniumdb_driver.graph_objects module. For example:

import millenniumdb_driver as mdb

my_iri = mdb.graph_objects.IRI("http://example.com")

# now you can use this IRI as a value

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

millenniumdb_driver-1.2.1.tar.gz (15.6 kB view details)

Uploaded Source

File details

Details for the file millenniumdb_driver-1.2.1.tar.gz.

File metadata

  • Download URL: millenniumdb_driver-1.2.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for millenniumdb_driver-1.2.1.tar.gz
Algorithm Hash digest
SHA256 ca8f1d011011720c36d0a865a6da5877b7b80fc531bac900b701af67393ff119
MD5 a114e7a0a09521f3679b42cee3fc8317
BLAKE2b-256 4627ab8d783152ae714496de7ee4a1e1c4d11e4674c89efe3fed80d0b74447c1

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