Skip to main content

Small functions for interacting with XTDB via requests http.

Project description

Table of Contents

  1. py xtdb
    1. Install:
    2. Sample Usage:
    3. Try it out
    4. Why

py xtdb

Small functions (and examples) for interacting with XTDB via requests http.

https://xtdb.com/docs/

Install:

pip istall py-xtdb

or

poetry add py-xtdb

Sample Usage:

q_results = query_edn(host="http://localhost:3001",
                      data="""
{:query {:find [?id ?name ?address]
         :keys [id name address]
         :where [[?id :xt/id]
                 [?id :name ?name]
                 [?id :address ?address]]
         :limit 2}}

    """)

print(q_results)

[{'address': '4681 Billy Parkway Suite 747\nNorth James, AR 25849',
  'id': 1,
  'name': 'Mr. David Mills'},
 {'address': '48596 Robert Walks\nWest Angelview, CO 76011',
  'id': 2,
  'name': 'Christopher Gregory'}]

If you’re looking to get query results into pandas fn `DataFrame` reads this sort of thing:

import pandas

print(pandas.DataFrame(q_results))
   id                 name                                            address
0   1      Mr. David Mills  4681 Billy Parkway Suite 747\nNorth James, AR ...
1   2  Christopher Gregory       48596 Robert Walks\nWest Angelview, CO 76011

Try it out

If you’d like to try out xt and python you can clone this repo, install the deps, start a local xt server, and walk through the jupyter notebooks in /nb/.

Here’s instructions/guidelines in more detail:

First, clone this repo locally and change to said directory:

git clone https://github.com/joefromct/py-xtdb
cd py-xtdb

Now we need to start xtdb in a terminal so the jupyter notebook has something to talk to.

The following command runs utilizing the `deps.edn` file which pulls in xt jars and runs with 2gb of memory.

# from same directory cloned above
clojure -X:xt

You’ll see some metrics flash to the screen occasionally saying what XT is up to. This is all setup with the file xtdb.edn. You can see here that xtdb.edn specifies data as the directory to store our database, and lucene full-text-search module(s).

So in summary, deps.edn pulls the dependencies you need, and xtdb.edn configures xt.

-—

Next lets get a jupyterlab environment running.

Open another terminal to this same directory.

Here, install python dependencies:

pip install -f requirements.txt

or use poetry (picks up the pyproject.toml… all same dir.)

poetry install

Now we should hopefully have jupyterlab on our path. Start it up like so:

jupyter-lab nb/demo.ipynb

From here you can step through the jupyter cells as per usual.

Have a look here.

Why

I’m looking to make `xtdb` more accessible to a python-first team, primarily with a focus on data science and/or data ingestion and document loading.

Some shops prefer to process data in python, and ideally they would have a gentle pathway/introduction to xtdb. This example has minimal clojure code, and all dependencies are driven just by deps.edn and xtdb.edn.

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

py-xtdb-0.5.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

py_xtdb-0.5.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file py-xtdb-0.5.1.tar.gz.

File metadata

  • Download URL: py-xtdb-0.5.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.17.4-arch1-1

File hashes

Hashes for py-xtdb-0.5.1.tar.gz
Algorithm Hash digest
SHA256 382c2ff956ec9edeabd195f0c4cbeccc628f5c1946e38913d67cf7b99fb34483
MD5 e05176b203a4f050b2c66e2bdd44df22
BLAKE2b-256 1dd1c6b4a5a237b150c0fab029a4477350e4966bd41b17d1447c47d42e77601f

See more details on using hashes here.

File details

Details for the file py_xtdb-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: py_xtdb-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.17.4-arch1-1

File hashes

Hashes for py_xtdb-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79dd41a8de7bf040b1ea3682fda5e3d5738d7911b1b356d95ee514f47d805c26
MD5 916d602527d88ad15e672cf65329d2c9
BLAKE2b-256 15a76fcbbd63892c538b905b593df8a43d3651086824a000d0640f89de10e06c

See more details on using hashes here.

Supported by

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