picopyn 0.2.0__tar.gz → 0.3.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/LICENSE +1 -1
- {picopyn-0.2.0/picopyn.egg-info → picopyn-0.3.0.dev1}/PKG-INFO +65 -37
- picopyn-0.3.0.dev1/README.md +158 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/README.md +6 -9
- picopyn-0.3.0.dev1/docs/async.md +3 -0
- picopyn-0.3.0.dev1/docs/explain.md +11 -0
- picopyn-0.3.0.dev1/docs/index.md +41 -0
- picopyn-0.3.0.dev1/docs/installation.md +19 -0
- picopyn-0.3.0.dev1/docs/sync.md +3 -0
- picopyn-0.3.0.dev1/picopyn/__init__.py +50 -0
- {picopyn-0.2.0/picopyn → picopyn-0.3.0.dev1/picopyn/asynchronous}/__init__.py +4 -1
- picopyn-0.3.0.dev1/picopyn/asynchronous/client.py +172 -0
- {picopyn-0.2.0/picopyn → picopyn-0.3.0.dev1/picopyn/asynchronous}/connection.py +26 -13
- {picopyn-0.2.0/picopyn → picopyn-0.3.0.dev1/picopyn/asynchronous}/pool.py +181 -218
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/picopyn/explain.py +2 -0
- picopyn-0.3.0.dev1/picopyn/synchronous/__init__.py +47 -0
- picopyn-0.3.0.dev1/picopyn/synchronous/connection.py +62 -0
- picopyn-0.3.0.dev1/picopyn/synchronous/cursor.py +100 -0
- picopyn-0.3.0.dev1/picopyn/synchronous/errors.py +38 -0
- picopyn-0.3.0.dev1/picopyn/utils/__init__.py +16 -0
- picopyn-0.3.0.dev1/picopyn/utils/discovery.py +42 -0
- picopyn-0.3.0.dev1/picopyn/utils/dsn.py +48 -0
- picopyn-0.3.0.dev1/picopyn/utils/queries.py +21 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1/picopyn.egg-info}/PKG-INFO +65 -37
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/picopyn.egg-info/SOURCES.txt +17 -15
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/picopyn.egg-info/requires.txt +11 -9
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/pyproject.toml +26 -15
- picopyn-0.2.0/README.md +0 -136
- picopyn-0.2.0/benchmark/requirements.txt +0 -3
- picopyn-0.2.0/docs/index.html +0 -7
- picopyn-0.2.0/docs/picopyn.html +0 -2193
- picopyn-0.2.0/docs/search.js +0 -46
- picopyn-0.2.0/picopyn/client.py +0 -156
- picopyn-0.2.0/requirements-dev.txt +0 -17
- picopyn-0.2.0/requirements.txt +0 -3
- picopyn-0.2.0/tests/test_client.py +0 -142
- picopyn-0.2.0/tests/test_connection.py +0 -115
- picopyn-0.2.0/tests/test_connection_pool.py +0 -786
- picopyn-0.2.0/tests/test_explain.py +0 -255
- picopyn-0.2.0/tests/test_sql_types.py +0 -79
- picopyn-0.2.0/tests/test_ssl.py +0 -230
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/AUTHORS.md +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/MANIFEST.in +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/bench.py +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/examples/10k_rows_1_thread_1_batch/overall_speed_time.png +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/examples/10k_rows_1_thread_1_batch/threads_speed_time.png +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/examples/1m_rows_10_threads_100_batch/errors_cumulative.png +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/examples/1m_rows_10_threads_100_batch/overall_speed_time.png +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/examples/1m_rows_10_threads_100_batch/threads_speed_time.png +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/benchmark/generate_data_to_csv.py +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/picopyn/ssl.py +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/picopyn.egg-info/dependency_links.txt +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/picopyn.egg-info/top_level.txt +0 -0
- {picopyn-0.2.0 → picopyn-0.3.0.dev1}/setup.cfg +0 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: picopyn
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
5
|
-
Author-email: Asya Lomakina <a.lomakina@picodata.io>, Igor Kuznetsov <i.kuznetsov@picodata.io>, Dmitriy Кoltsov <dkoltsov@picodata.io>
|
|
6
|
-
License: BSD-2-Clause
|
|
7
|
-
Project-URL:
|
|
3
|
+
Version: 0.3.0.dev1
|
|
4
|
+
Summary: Python connector for working with the distributed Picodata database.
|
|
5
|
+
Author-email: Asya Lomakina <a.lomakina@picodata.io>, Igor Kuznetsov <i.kuznetsov@picodata.io>, Dmitriy Кoltsov <dkoltsov@picodata.io>, Daniil Gorlyakov <d.gorlyakov@picodata.io>
|
|
6
|
+
License-Expression: BSD-2-Clause
|
|
7
|
+
Project-URL: Source, https://git.picodata.io/solution/picopyn
|
|
8
|
+
Project-URL: Documentation, https://picopyn.readthedocs.io/en/stable/
|
|
9
|
+
Project-URL: Changelog, https://git.picodata.io/core/drivers/picopyn/-/blob/main/CHANGELOG.md
|
|
8
10
|
Keywords: database,picodata
|
|
9
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
-
Classifier: License :: OSI Approved :: BSD License
|
|
11
12
|
Classifier: Operating System :: OS Independent
|
|
12
13
|
Classifier: Development Status :: 3 - Alpha
|
|
13
14
|
Classifier: Intended Audience :: Developers
|
|
@@ -20,9 +21,7 @@ License-File: AUTHORS.md
|
|
|
20
21
|
Requires-Dist: async-timeout==5.0.1
|
|
21
22
|
Requires-Dist: asyncpg==0.30.0
|
|
22
23
|
Requires-Dist: typing_extensions==4.12.2; python_version == "3.10"
|
|
23
|
-
|
|
24
|
-
Requires-Dist: gssapi; platform_system != "Windows" and extra == "gssauth"
|
|
25
|
-
Requires-Dist: sspilib; platform_system == "Windows" and extra == "gssauth"
|
|
24
|
+
Requires-Dist: psycopg[binary]==3.3.4
|
|
26
25
|
Provides-Extra: test
|
|
27
26
|
Requires-Dist: pytest==8.3.5; extra == "test"
|
|
28
27
|
Requires-Dist: pytest-asyncio==0.25.3; extra == "test"
|
|
@@ -30,37 +29,56 @@ Requires-Dist: ruff==0.11.13; extra == "test"
|
|
|
30
29
|
Requires-Dist: mypy==1.16.0; extra == "test"
|
|
31
30
|
Requires-Dist: black==25.1.0; extra == "test"
|
|
32
31
|
Provides-Extra: docs
|
|
33
|
-
Requires-Dist:
|
|
34
|
-
Requires-Dist:
|
|
32
|
+
Requires-Dist: mkdocs<2.0,>=1.0; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocs-material; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocstrings[python]; extra == "docs"
|
|
35
|
+
Provides-Extra: benchmark
|
|
36
|
+
Requires-Dist: numpy==1.24.4; extra == "benchmark"
|
|
37
|
+
Requires-Dist: matplotlib==3.8.4; extra == "benchmark"
|
|
38
|
+
Requires-Dist: colorama==0.4.6; extra == "benchmark"
|
|
39
|
+
Provides-Extra: publish
|
|
40
|
+
Requires-Dist: pypi-cleanup; extra == "publish"
|
|
35
41
|
Dynamic: license-file
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
[](https://pypi.org/project/picopyn/)
|
|
44
|
+
[](https://pypi.org/project/picopyn)
|
|
45
|
+
[](https://picopyn.readthedocs.io)
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
# Picopyn - Picodata Python driver
|
|
48
|
+
|
|
49
|
+
**Picopyn** is a Python package for working with the distributed [Picodata](https://picodata.io/en/) database.
|
|
40
50
|
|
|
41
51
|
## Features
|
|
42
52
|
* Connection pooling with configurable pool size
|
|
43
53
|
* Optional automatic node discovery
|
|
44
54
|
* Pluggable load-balancing strategies
|
|
45
|
-
*
|
|
55
|
+
* Provides both asynchronous API (based on [asyncpg](https://github.com/MagicStack/asyncpg)) and synchronous API (based on [psycopg](https://www.psycopg.org/))
|
|
46
56
|
|
|
47
57
|
## Navigation
|
|
48
|
-
* [Installation](#
|
|
49
|
-
* [Quickstart](#
|
|
50
|
-
* [Development](#
|
|
51
|
-
* [
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
* [Installation](#installation)
|
|
59
|
+
* [Quickstart](#quickstart)
|
|
60
|
+
* [Development](#development)
|
|
61
|
+
* [Docs](#documentation)
|
|
62
|
+
* [Lint](#how-to-write-code)
|
|
63
|
+
* [Test](#how-to-test)
|
|
64
|
+
* [Debug](#how-to-debug)
|
|
65
|
+
* [Benchmark](#benchmark)
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
pip install picopyn
|
|
71
|
+
```
|
|
54
72
|
|
|
55
|
-
|
|
73
|
+
Or from source:
|
|
56
74
|
|
|
57
|
-
```
|
|
75
|
+
```sh
|
|
58
76
|
git clone https://git.picodata.io/solution/picopyn.git
|
|
59
77
|
cd picopyn
|
|
60
|
-
|
|
78
|
+
pip install -e .
|
|
61
79
|
```
|
|
62
80
|
|
|
63
|
-
##
|
|
81
|
+
## Quickstart
|
|
64
82
|
|
|
65
83
|
```python
|
|
66
84
|
import asyncio
|
|
@@ -86,22 +104,31 @@ async def main():
|
|
|
86
104
|
asyncio.run(main())
|
|
87
105
|
```
|
|
88
106
|
|
|
89
|
-
##
|
|
107
|
+
## Development
|
|
108
|
+
For development we use [uv](https://docs.astral.sh/uv/getting-started/installation/) as package manager and [docker compose](https://docs.docker.com/compose/install/) for test environment.
|
|
90
109
|
|
|
91
|
-
|
|
110
|
+
To install development dependencies:
|
|
92
111
|
```bash
|
|
93
|
-
|
|
112
|
+
uv sync --extra test
|
|
94
113
|
```
|
|
95
114
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
To update documentation:
|
|
115
|
+
Inside the test container, run the same command to keep dependencies up to date if the image is outdated:
|
|
99
116
|
```bash
|
|
100
|
-
make
|
|
117
|
+
make shell
|
|
118
|
+
# inside the container:
|
|
119
|
+
make install
|
|
101
120
|
```
|
|
102
121
|
|
|
103
|
-
|
|
122
|
+
### Documentation
|
|
123
|
+
|
|
124
|
+
The documentation is written in Markdown and built with [MkDocs](https://www.mkdocs.org/) using the [Material theme](https://squidfunk.github.io/mkdocs-material/). API reference is generated automatically from docstrings via [mkdocstrings](https://mkdocstrings.github.io/).
|
|
125
|
+
|
|
126
|
+
Published documentation is available at **[picopyn.readthedocs.io](https://picopyn.readthedocs.io/en/stable/)**.
|
|
127
|
+
|
|
128
|
+
Source files are located in the `docs/` directory. To work on docs locally, install the docs dependencies and start the live-reload server:
|
|
129
|
+
|
|
104
130
|
```bash
|
|
131
|
+
uv sync --extra docs
|
|
105
132
|
make doc
|
|
106
133
|
```
|
|
107
134
|
|
|
@@ -115,7 +142,7 @@ We use several tools to ensure code style and type safety.
|
|
|
115
142
|
To check code style and static types:
|
|
116
143
|
```bash
|
|
117
144
|
make lint
|
|
118
|
-
|
|
145
|
+
```
|
|
119
146
|
|
|
120
147
|
To automatically fix formatting and style issues:
|
|
121
148
|
|
|
@@ -124,6 +151,7 @@ make fmt
|
|
|
124
151
|
```
|
|
125
152
|
|
|
126
153
|
### How to test
|
|
154
|
+
We use [docker compose](https://docs.docker.com/compose/install/) for test environment.
|
|
127
155
|
|
|
128
156
|
Run the general test suite:
|
|
129
157
|
|
|
@@ -145,8 +173,7 @@ This will:
|
|
|
145
173
|
|
|
146
174
|
|
|
147
175
|
### How to debug
|
|
148
|
-
|
|
149
|
-
Do not forget run environment via `make env`
|
|
176
|
+
Do not forget to run the environment via `make env`
|
|
150
177
|
|
|
151
178
|
For debugging purposes:
|
|
152
179
|
|
|
@@ -165,8 +192,9 @@ python -m asyncio
|
|
|
165
192
|
3. To connect directly to Picodata:
|
|
166
193
|
|
|
167
194
|
```bash
|
|
168
|
-
picodata admin tmp/picodata-1-1/admin.sock
|
|
195
|
+
picodata admin tmp/data/picodata-1-1/admin.sock
|
|
169
196
|
```
|
|
170
|
-
|
|
197
|
+
|
|
198
|
+
## Benchmark
|
|
171
199
|
|
|
172
200
|
Benchmark instructions and usage examples are available [here](benchmark/README.md).
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
[](https://pypi.org/project/picopyn/)
|
|
2
|
+
[](https://pypi.org/project/picopyn)
|
|
3
|
+
[](https://picopyn.readthedocs.io)
|
|
4
|
+
|
|
5
|
+
# Picopyn - Picodata Python driver
|
|
6
|
+
|
|
7
|
+
**Picopyn** is a Python package for working with the distributed [Picodata](https://picodata.io/en/) database.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
* Connection pooling with configurable pool size
|
|
11
|
+
* Optional automatic node discovery
|
|
12
|
+
* Pluggable load-balancing strategies
|
|
13
|
+
* Provides both asynchronous API (based on [asyncpg](https://github.com/MagicStack/asyncpg)) and synchronous API (based on [psycopg](https://www.psycopg.org/))
|
|
14
|
+
|
|
15
|
+
## Navigation
|
|
16
|
+
* [Installation](#installation)
|
|
17
|
+
* [Quickstart](#quickstart)
|
|
18
|
+
* [Development](#development)
|
|
19
|
+
* [Docs](#documentation)
|
|
20
|
+
* [Lint](#how-to-write-code)
|
|
21
|
+
* [Test](#how-to-test)
|
|
22
|
+
* [Debug](#how-to-debug)
|
|
23
|
+
* [Benchmark](#benchmark)
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pip install picopyn
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or from source:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
git clone https://git.picodata.io/solution/picopyn.git
|
|
35
|
+
cd picopyn
|
|
36
|
+
pip install -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import asyncio
|
|
43
|
+
from picopyn import Client
|
|
44
|
+
|
|
45
|
+
async def main():
|
|
46
|
+
# create and connect client to the picodata cluster
|
|
47
|
+
client = Client(dsn="postgresql://admin:pass@localhost:5432")
|
|
48
|
+
await client.connect()
|
|
49
|
+
|
|
50
|
+
# execute DDL operations
|
|
51
|
+
await client.execute('''
|
|
52
|
+
CREATE TABLE "warehouse" (id INTEGER NOT NULL, item TEXT NOT NULL, PRIMARY KEY (id)) USING memtx DISTRIBUTED BY (id) OPTION (TIMEOUT = 3.0);
|
|
53
|
+
''')
|
|
54
|
+
|
|
55
|
+
# execute DML operations
|
|
56
|
+
await client.execute('INSERT INTO \"warehouse\" VALUES ($1::int, $2::varchar)', 1, "test")
|
|
57
|
+
rows = await client.fetch('SELECT * FROM \"warehouse\"')
|
|
58
|
+
print(rows)
|
|
59
|
+
|
|
60
|
+
await client.close()
|
|
61
|
+
|
|
62
|
+
asyncio.run(main())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
For development we use [uv](https://docs.astral.sh/uv/getting-started/installation/) as package manager and [docker compose](https://docs.docker.com/compose/install/) for test environment.
|
|
67
|
+
|
|
68
|
+
To install development dependencies:
|
|
69
|
+
```bash
|
|
70
|
+
uv sync --extra test
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Inside the test container, run the same command to keep dependencies up to date if the image is outdated:
|
|
74
|
+
```bash
|
|
75
|
+
make shell
|
|
76
|
+
# inside the container:
|
|
77
|
+
make install
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Documentation
|
|
81
|
+
|
|
82
|
+
The documentation is written in Markdown and built with [MkDocs](https://www.mkdocs.org/) using the [Material theme](https://squidfunk.github.io/mkdocs-material/). API reference is generated automatically from docstrings via [mkdocstrings](https://mkdocstrings.github.io/).
|
|
83
|
+
|
|
84
|
+
Published documentation is available at **[picopyn.readthedocs.io](https://picopyn.readthedocs.io/en/stable/)**.
|
|
85
|
+
|
|
86
|
+
Source files are located in the `docs/` directory. To work on docs locally, install the docs dependencies and start the live-reload server:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
uv sync --extra docs
|
|
90
|
+
make doc
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### How to write code
|
|
94
|
+
|
|
95
|
+
We use several tools to ensure code style and type safety.
|
|
96
|
+
* ruff — code style, lint checks and automatic lint fixing
|
|
97
|
+
* mypy — static type checking
|
|
98
|
+
* black — code formatting
|
|
99
|
+
|
|
100
|
+
To check code style and static types:
|
|
101
|
+
```bash
|
|
102
|
+
make lint
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
To automatically fix formatting and style issues:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
make fmt
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### How to test
|
|
112
|
+
We use [docker compose](https://docs.docker.com/compose/install/) for test environment.
|
|
113
|
+
|
|
114
|
+
Run the general test suite:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
make test
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
or run SSL tests:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
make test-ssl
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This will:
|
|
127
|
+
|
|
128
|
+
1. Start required test containers (Picodata cluster and test-runner) using Docker Compose
|
|
129
|
+
|
|
130
|
+
2. Execute tests using pytest
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### How to debug
|
|
134
|
+
Do not forget to run the environment via `make env`
|
|
135
|
+
|
|
136
|
+
For debugging purposes:
|
|
137
|
+
|
|
138
|
+
1. Open a bash shell in the test container:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
make shell
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
2. For interactive Python (with asyncio support) run inside of container:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
python -m asyncio
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
3. To connect directly to Picodata:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
picodata admin tmp/data/picodata-1-1/admin.sock
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Benchmark
|
|
157
|
+
|
|
158
|
+
Benchmark instructions and usage examples are available [here](benchmark/README.md).
|
|
@@ -26,21 +26,18 @@ This directory contains a benchmark tool for measuring Picopyn insert performanc
|
|
|
26
26
|
## <a name="prerequisites"></a>Prerequisites
|
|
27
27
|
|
|
28
28
|
- Python 3.10+
|
|
29
|
-
- Install project dependencies (including `picopyn` and deps from `./requirements.txt`):
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
All commands below are for the test-runner container. To enter it:
|
|
32
31
|
|
|
33
32
|
```bash
|
|
34
|
-
# root
|
|
33
|
+
# from project root
|
|
35
34
|
make shell
|
|
35
|
+
cd benchmark
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Sync dependencies (in case the image is outdated):
|
|
39
39
|
```bash
|
|
40
|
-
|
|
41
|
-
cd benchmark
|
|
42
|
-
# not necessary for docker container
|
|
43
|
-
pip install -r requirements.txt
|
|
40
|
+
uv sync --extra test --extra benchmark
|
|
44
41
|
```
|
|
45
42
|
|
|
46
43
|
## <a name="csv"></a>CSV Input Format
|
|
@@ -211,7 +208,7 @@ For a big dataset you may need to inscrease Picodata memory. Use:
|
|
|
211
208
|
|
|
212
209
|
```bash
|
|
213
210
|
# connect to picodata instance
|
|
214
|
-
picodata admin tmp/data/picodata-1-1/admin.sock
|
|
211
|
+
picodata admin ../tmp/data/picodata-1-1/admin.sock
|
|
215
212
|
# inside picodata console switch to LUA
|
|
216
213
|
(admin) sql> \lua
|
|
217
214
|
Language switched to lua
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# picopyn
|
|
2
|
+
|
|
3
|
+
**picopyn** is a Python connector for working with the distributed [Picodata](https://picodata.io/en/) database.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Connection pooling with configurable pool size
|
|
8
|
+
- Optional automatic node discovery
|
|
9
|
+
- Pluggable load-balancing strategies
|
|
10
|
+
- Asynchronous API based on [asyncpg](https://github.com/MagicStack/asyncpg)
|
|
11
|
+
- Synchronous API based on [psycopg](https://www.psycopg.org/)
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pip install picopyn
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import asyncio
|
|
21
|
+
from picopyn import Client
|
|
22
|
+
|
|
23
|
+
async def main():
|
|
24
|
+
client = Client(dsn="postgresql://admin:pass@localhost:5432")
|
|
25
|
+
await client.connect()
|
|
26
|
+
|
|
27
|
+
await client.execute('''
|
|
28
|
+
CREATE TABLE "warehouse" (id INTEGER NOT NULL, item TEXT NOT NULL, PRIMARY KEY (id))
|
|
29
|
+
USING memtx DISTRIBUTED BY (id) OPTION (TIMEOUT = 3.0);
|
|
30
|
+
''')
|
|
31
|
+
|
|
32
|
+
await client.execute('INSERT INTO "warehouse" VALUES ($1::int, $2::varchar)', 1, "test")
|
|
33
|
+
rows = await client.fetch('SELECT * FROM "warehouse"')
|
|
34
|
+
print(rows)
|
|
35
|
+
|
|
36
|
+
await client.close()
|
|
37
|
+
|
|
38
|
+
asyncio.run(main())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
See [Installation](installation.md) for all install options.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
## Requirements
|
|
4
|
+
|
|
5
|
+
- Python 3.10+
|
|
6
|
+
|
|
7
|
+
## Install from PyPI
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pip install picopyn
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Install from source
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
git clone https://git.picodata.io/solution/picopyn.git
|
|
17
|
+
cd picopyn
|
|
18
|
+
pip install -e .
|
|
19
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Picopyn is a Python driver for working with the Picodata database.
|
|
2
|
+
|
|
3
|
+
It provides both [asynchronous](async.md) and [synchronous](sync.md) APIs for connecting to a Picodata cluster, executing queries and working with connection pools.
|
|
4
|
+
|
|
5
|
+
See [picodata docs](https://docs.picodata.io/picodata/devel/).
|
|
6
|
+
|
|
7
|
+
## Logging
|
|
8
|
+
|
|
9
|
+
The library uses standard Python logging under the `picopyn` logger name. No handlers are configured by default — it is up to the application to configure logging. You can do it in several ways:
|
|
10
|
+
|
|
11
|
+
- configure format and output via root logger (the simplest approach):
|
|
12
|
+
```python
|
|
13
|
+
import logging
|
|
14
|
+
logging.basicConfig(level=logging.DEBUG, format="%(levelname)-8s %(name)s — %(message)s")
|
|
15
|
+
logging.getLogger("picopyn").setLevel(logging.DEBUG)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- add a handler directly to the `picopyn` logger without affecting the root logger:
|
|
19
|
+
```python
|
|
20
|
+
import logging
|
|
21
|
+
handler = logging.StreamHandler()
|
|
22
|
+
handler.setFormatter(logging.Formatter("%(levelname)-8s %(name)s — %(message)s"))
|
|
23
|
+
logging.getLogger("picopyn").addHandler(handler)
|
|
24
|
+
logging.getLogger("picopyn").setLevel(logging.DEBUG)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- if a handler is already configured elsewhere in the application, just set the level:
|
|
28
|
+
```python
|
|
29
|
+
logging.getLogger("picopyn").setLevel(logging.DEBUG)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- set log level for a specific module:
|
|
33
|
+
```python
|
|
34
|
+
logging.getLogger("picopyn.asynchronous.pool").setLevel(logging.DEBUG)
|
|
35
|
+
```
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
import logging
|
|
39
|
+
|
|
40
|
+
from .asynchronous import Client, Connection, ExplainPlan, ExplainRawPlan, Pool
|
|
41
|
+
|
|
42
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
"Client",
|
|
46
|
+
"Connection",
|
|
47
|
+
"ExplainPlan",
|
|
48
|
+
"ExplainRawPlan",
|
|
49
|
+
"Pool",
|
|
50
|
+
]
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
"""Async API based on asyncpg for connection management, pools, and client classes."""
|
|
2
|
+
|
|
3
|
+
from picopyn.explain import ExplainPlan, ExplainRawPlan
|
|
4
|
+
|
|
1
5
|
from .client import Client
|
|
2
6
|
from .connection import Connection
|
|
3
|
-
from .explain import ExplainPlan, ExplainRawPlan
|
|
4
7
|
from .pool import Pool
|
|
5
8
|
|
|
6
9
|
__all__ = [
|