|
1 | | -============== |
2 | | -NuoDB - Python |
3 | | -============== |
4 | | - |
5 | | -.. image::https://circleci.com/gh/nuodb/nuodb-python.svg?style=svg |
6 | | - :target: https://circleci.com/gh/nuodb/nuodb-python |
7 | | - :alt: Test Results |
8 | | -.. image:: https://gitlab.com/cadmin/nuodb-python/badges/master/pipeline.svg |
9 | | - :target: https://gitlab.com/nuodb-mirror/nuodb-python/-/jobs |
10 | | - :alt: Dependency Verification |
11 | | - |
12 | | -.. contents:: |
13 | | - |
14 | | -This package contains the community driven pure-Python NuoDB_ client library |
15 | | -that provides a standard `PEP 249`_ SQL API. This is a community driven driver |
16 | | -with limited support and testing from NuoDB. |
17 | | - |
18 | | -Requirements |
19 | | ------------- |
20 | | - |
21 | | -* Python -- one of the following: |
22 | | - |
23 | | - - CPython_ >= 2.7 |
24 | | - |
25 | | -* NuoDB -- one of the following: |
26 | | - |
27 | | - - NuoDB_ >= 2.0.4 |
28 | | - |
29 | | -If you don't have a NuoDB domain available you can create one using the Docker |
30 | | -image on DockerHub. See `Quick Start Guides / Docker <https://doc.nuodb.com/nuodb/latest/quick-start-guide/docker/>`_. |
31 | | - |
32 | | -Installation |
33 | | ------------- |
34 | | - |
35 | | -The current stable release is available on PyPI and can be installed with |
36 | | -``pip``:: |
37 | | - |
38 | | - $ pip install pynuodb |
39 | | - |
40 | | -Alternatively (e.g. if ``pip`` is not available), a tarball can be downloaded |
41 | | -from GitHub and installed with Setuptools:: |
42 | | - |
43 | | - $ curl -L https://github.com/nuodb/nuodb-python/archive/master.tar.gz | tar xz |
44 | | - $ cd nuodb-python* |
45 | | - $ python setup.py install |
46 | | - # The folder nuodb-python* can be safely removed now. |
47 | | - |
48 | | -Example |
49 | | -------- |
50 | | - |
51 | | -Here is an example using the `PEP 249`_ API that creates some tables, inserts |
52 | | -some data, runs a query, and cleans up after itself: |
53 | | - |
54 | | -.. code:: python |
55 | | -
|
56 | | - import pynuodb |
57 | | -
|
58 | | - options = {"schema": "test"} |
59 | | - connect_kw_args = {'database': "test", 'host': "localhost", 'user': "dba", 'password': "dba", 'options': options} |
60 | | -
|
61 | | - connection = pynuodb.connect(**connect_kw_args) |
62 | | - cursor = connection.cursor() |
63 | | - try: |
64 | | - stmt_drop = "DROP TABLE IF EXISTS names" |
65 | | - cursor.execute(stmt_drop) |
66 | | -
|
67 | | - stmt_create = """ |
68 | | - CREATE TABLE names ( |
69 | | - id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
70 | | - name VARCHAR(30) DEFAULT '' NOT NULL, |
71 | | - age INTEGER DEFAULT 0 |
72 | | - )""" |
73 | | - cursor.execute(stmt_create) |
74 | | -
|
75 | | - names = (('Greg', 17,), ('Marsha', 16,), ('Jan', 14,)) |
76 | | - stmt_insert = "INSERT INTO names (name, age) VALUES (?, ?)" |
77 | | - cursor.executemany(stmt_insert, names) |
78 | | -
|
79 | | - connection.commit() |
80 | | -
|
81 | | - age_limit = 15 |
82 | | - stmt_select = "SELECT id, name FROM names where age > ? ORDER BY id" |
83 | | - cursor.execute(stmt_select, (age_limit,)) |
84 | | - print("Results:") |
85 | | - for row in cursor.fetchall(): |
86 | | - print("%d | %s" % (row[0], row[1])) |
87 | | -
|
88 | | - finally: |
89 | | - cursor.execute(stmt_drop) |
90 | | - cursor.close() |
91 | | - connection.close() |
92 | | -
|
93 | | -For further information on getting started with NuoDB, please refer to the Documentation_. |
94 | | - |
95 | | -Resources |
96 | | ---------- |
97 | | - |
98 | | -DB-API 2.0: https://www.python.org/dev/peps/pep-0249/ |
99 | | - |
100 | | -NuoDB Documentation: https://doc.nuodb.com/nuodb/latest/introduction-to-nuodb/ |
101 | | - |
102 | | -License |
103 | | -------- |
104 | | - |
105 | | -PyNuoDB is licensed under a `BSD 3-Clause License <https://github.com/nuodb/nuodb-python/blob/master/LICENSE>`_. |
106 | | - |
107 | | -.. _Documentation: https://doc.nuodb.com/nuodb/latest/introduction-to-nuodb/ |
108 | | -.. _NuoDB: https://www.nuodb.com/ |
109 | | -.. _CPython: https://www.python.org/ |
110 | | -.. _PEP 249: https://www.python.org/dev/peps/pep-0249/ |
| 1 | +============== |
| 2 | +NuoDB - Python |
| 3 | +============== |
| 4 | + |
| 5 | +.. image::https://circleci.com/gh/nuodb/nuodb-python.svg?style=svg |
| 6 | + :target: https://circleci.com/gh/nuodb/nuodb-python |
| 7 | + :alt: Test Results |
| 8 | +.. image:: https://gitlab.com/cadmin/nuodb-python/badges/master/pipeline.svg |
| 9 | + :target: https://gitlab.com/nuodb-mirror/nuodb-python/-/jobs |
| 10 | + :alt: Dependency Verification |
| 11 | + |
| 12 | +.. contents:: |
| 13 | + |
| 14 | +This package contains the community driven pure-Python NuoDB_ client library |
| 15 | +that provides a standard `PEP 249`_ SQL API. This is a community driven driver |
| 16 | +with limited support and testing from NuoDB. |
| 17 | + |
| 18 | +Requirements |
| 19 | +------------ |
| 20 | + |
| 21 | +* Python -- one of the following: |
| 22 | + |
| 23 | + - CPython_ >= 2.7 |
| 24 | + |
| 25 | +* NuoDB -- one of the following: |
| 26 | + |
| 27 | + - NuoDB_ >= 2.0.4 |
| 28 | + |
| 29 | +If you don't have a NuoDB domain available you can create one using the Docker |
| 30 | +image on DockerHub. See `Quick Start Guides / Docker <https://doc.nuodb.com/nuodb/latest/quick-start-guide/docker/>`_. |
| 31 | + |
| 32 | +Installation |
| 33 | +------------ |
| 34 | + |
| 35 | +The current stable release is available on PyPI and can be installed with |
| 36 | +``pip``:: |
| 37 | + |
| 38 | + $ pip install pynuodb |
| 39 | + |
| 40 | +Alternatively (e.g. if ``pip`` is not available), a tarball can be downloaded |
| 41 | +from GitHub and installed with Setuptools:: |
| 42 | + |
| 43 | + $ curl -L https://github.com/nuodb/nuodb-python/archive/master.tar.gz | tar xz |
| 44 | + $ cd nuodb-python* |
| 45 | + $ python setup.py install |
| 46 | + # The folder nuodb-python* can be safely removed now. |
| 47 | + |
| 48 | +Example |
| 49 | +------- |
| 50 | + |
| 51 | +Here is an example using the `PEP 249`_ API that creates some tables, inserts |
| 52 | +some data, runs a query, and cleans up after itself: |
| 53 | + |
| 54 | +.. code:: python |
| 55 | +
|
| 56 | + import pynuodb |
| 57 | +
|
| 58 | + options = {"schema": "test"} |
| 59 | + connect_kw_args = {'database': "test", 'host': "localhost", 'user': "dba", 'password': "dba", 'options': options} |
| 60 | +
|
| 61 | + connection = pynuodb.connect(**connect_kw_args) |
| 62 | + cursor = connection.cursor() |
| 63 | + try: |
| 64 | + stmt_drop = "DROP TABLE IF EXISTS names" |
| 65 | + cursor.execute(stmt_drop) |
| 66 | +
|
| 67 | + stmt_create = """ |
| 68 | + CREATE TABLE names ( |
| 69 | + id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 70 | + name VARCHAR(30) DEFAULT '' NOT NULL, |
| 71 | + age INTEGER DEFAULT 0 |
| 72 | + )""" |
| 73 | + cursor.execute(stmt_create) |
| 74 | +
|
| 75 | + names = (('Greg', 17,), ('Marsha', 16,), ('Jan', 14,)) |
| 76 | + stmt_insert = "INSERT INTO names (name, age) VALUES (?, ?)" |
| 77 | + cursor.executemany(stmt_insert, names) |
| 78 | +
|
| 79 | + connection.commit() |
| 80 | +
|
| 81 | + age_limit = 15 |
| 82 | + stmt_select = "SELECT id, name FROM names where age > ? ORDER BY id" |
| 83 | + cursor.execute(stmt_select, (age_limit,)) |
| 84 | + print("Results:") |
| 85 | + for row in cursor.fetchall(): |
| 86 | + print("%d | %s" % (row[0], row[1])) |
| 87 | +
|
| 88 | + finally: |
| 89 | + cursor.execute(stmt_drop) |
| 90 | + cursor.close() |
| 91 | + connection.close() |
| 92 | +
|
| 93 | +For further information on getting started with NuoDB, please refer to the Documentation_. |
| 94 | + |
| 95 | +Resources |
| 96 | +--------- |
| 97 | + |
| 98 | +DB-API 2.0: https://www.python.org/dev/peps/pep-0249/ |
| 99 | + |
| 100 | +NuoDB Documentation: https://doc.nuodb.com/nuodb/latest/introduction-to-nuodb/ |
| 101 | + |
| 102 | +License |
| 103 | +------- |
| 104 | + |
| 105 | +PyNuoDB is licensed under a `BSD 3-Clause License <https://github.com/nuodb/nuodb-python/blob/master/LICENSE>`_. |
| 106 | + |
| 107 | +.. _Documentation: https://doc.nuodb.com/nuodb/latest/introduction-to-nuodb/ |
| 108 | +.. _NuoDB: https://www.nuodb.com/ |
| 109 | +.. _CPython: https://www.python.org/ |
| 110 | +.. _PEP 249: https://www.python.org/dev/peps/pep-0249/ |
0 commit comments