database-wrapper-pgsql 0.3.147__tar.gz → 0.4.1__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.
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/PKG-INFO +4 -4
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/__init__.py +2 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/connector.py +64 -20
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql.egg-info/PKG-INFO +4 -4
- database_wrapper_pgsql-0.4.1/database_wrapper_pgsql.egg-info/requires.txt +3 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/pyproject.toml +7 -5
- database_wrapper_pgsql-0.3.147/database_wrapper_pgsql.egg-info/requires.txt +0 -3
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/LICENSE +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/README.md +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/db_wrapper_pgsql.py +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/db_wrapper_pgsql_async.py +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/db_wrapper_pgsql_mixin.py +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/pg_introspector.py +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/py.typed +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/type_mapping.py +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql.egg-info/SOURCES.txt +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql.egg-info/dependency_links.txt +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql.egg-info/top_level.txt +0 -0
- {database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/setup.cfg +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: database_wrapper_pgsql
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: database_wrapper for PostgreSQL database
|
|
5
5
|
Author-email: Gints Murans <gm@gm.lv>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/4Apps/py_database_wrapper
|
|
8
8
|
Project-URL: Documentation, https://github.com/4Apps/py_database_wrapper
|
|
9
|
-
Project-URL: Changes, https://github.com/4Apps/py_database_wrapper
|
|
9
|
+
Project-URL: Changes, https://github.com/4Apps/py_database_wrapper/blob/master/CHANGELOG.md
|
|
10
10
|
Project-URL: Code, https://github.com/4Apps/py_database_wrapper
|
|
11
11
|
Project-URL: Issue Tracker, https://github.com/4Apps/py_database_wrapper/issues
|
|
12
12
|
Project-URL: Download, https://pypi.org/project/database_wrapper/
|
|
@@ -32,9 +32,9 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
32
32
|
Requires-Python: >=3.8
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
34
|
License-File: LICENSE
|
|
35
|
-
Requires-Dist: database_wrapper==0.
|
|
35
|
+
Requires-Dist: database_wrapper==0.4.1
|
|
36
36
|
Requires-Dist: psycopg[binary]>=3.2.0
|
|
37
|
-
Requires-Dist: psycopg
|
|
37
|
+
Requires-Dist: psycopg-pool>=3.3.0
|
|
38
38
|
Dynamic: license-file
|
|
39
39
|
|
|
40
40
|
# database_wrapper_pgsql
|
{database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/__init__.py
RENAMED
|
@@ -20,6 +20,7 @@ from .connector import (
|
|
|
20
20
|
Pgsql,
|
|
21
21
|
PgsqlAsync,
|
|
22
22
|
PgsqlConfig,
|
|
23
|
+
PgsqlPassword,
|
|
23
24
|
PgsqlWithPooling,
|
|
24
25
|
PgsqlWithPoolingAsync,
|
|
25
26
|
)
|
|
@@ -52,5 +53,6 @@ __all__ = [
|
|
|
52
53
|
PgDictRow,
|
|
53
54
|
# Helpers
|
|
54
55
|
PgsqlConfig,
|
|
56
|
+
PgsqlPassword,
|
|
55
57
|
PostgresIntrospector,
|
|
56
58
|
]
|
{database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/connector.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
|
|
2
|
+
import inspect
|
|
3
|
+
from collections.abc import AsyncIterator, Awaitable, Callable, Iterator
|
|
3
4
|
from contextlib import asynccontextmanager, contextmanager
|
|
4
5
|
from contextvars import ContextVar
|
|
5
6
|
from typing import Any, NotRequired, TypedDict, cast
|
|
@@ -23,11 +24,16 @@ PgConnectionTypeAsync = PgConnectionAsync[PgDictRow]
|
|
|
23
24
|
PgCursorTypeAsync = PgCursorAsync[PgDictRow]
|
|
24
25
|
|
|
25
26
|
|
|
27
|
+
PgsqlPassword = str | Callable[[], str] | Callable[[], Awaitable[str]]
|
|
28
|
+
""" A password, or a callable called for every new connection - a short-lived token never goes stale in the pool.
|
|
29
|
+
Async callables work with the async classes only. """
|
|
30
|
+
|
|
31
|
+
|
|
26
32
|
class PgsqlConfig(TypedDict):
|
|
27
33
|
hostname: str
|
|
28
34
|
port: NotRequired[int]
|
|
29
35
|
username: str
|
|
30
|
-
password:
|
|
36
|
+
password: PgsqlPassword
|
|
31
37
|
database: str
|
|
32
38
|
ssl: NotRequired[str]
|
|
33
39
|
kwargs: NotRequired[dict[str, Any]]
|
|
@@ -37,6 +43,40 @@ class PgsqlConfig(TypedDict):
|
|
|
37
43
|
pool_kwargs: NotRequired[dict[str, Any]]
|
|
38
44
|
|
|
39
45
|
|
|
46
|
+
def _resolve_password(password: PgsqlPassword) -> str:
|
|
47
|
+
if not callable(password):
|
|
48
|
+
return password
|
|
49
|
+
|
|
50
|
+
resolved = password()
|
|
51
|
+
if inspect.isawaitable(resolved):
|
|
52
|
+
if inspect.iscoroutine(resolved):
|
|
53
|
+
resolved.close()
|
|
54
|
+
raise TypeError("An async password callable needs an async PostgreSQL class")
|
|
55
|
+
|
|
56
|
+
return resolved
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def _resolve_password_async(password: PgsqlPassword) -> str:
|
|
60
|
+
if not callable(password):
|
|
61
|
+
return password
|
|
62
|
+
|
|
63
|
+
resolved = password()
|
|
64
|
+
if inspect.isawaitable(resolved):
|
|
65
|
+
return await resolved
|
|
66
|
+
|
|
67
|
+
return resolved
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _pool_conninfo(config: PgsqlConfig, password: str, connection_timeout: int, application_name: str) -> str:
|
|
71
|
+
return (
|
|
72
|
+
f"postgresql://{quote(config['username'])}:{quote(password)}"
|
|
73
|
+
f"@{config['hostname']}:{config['port']}"
|
|
74
|
+
f"/{quote(config['database'])}?connect_timeout={connection_timeout}"
|
|
75
|
+
f"&application_name={quote(application_name)}"
|
|
76
|
+
f"&sslmode={config['ssl']}"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
40
80
|
class Pgsql(DatabaseBackend):
|
|
41
81
|
"""
|
|
42
82
|
PostgreSQL database implementation.
|
|
@@ -90,7 +130,7 @@ class Pgsql(DatabaseBackend):
|
|
|
90
130
|
port=self.config["port"],
|
|
91
131
|
sslmode=self.config["ssl"],
|
|
92
132
|
user=self.config["username"],
|
|
93
|
-
password=self.config["password"],
|
|
133
|
+
password=_resolve_password(self.config["password"]),
|
|
94
134
|
dbname=self.config["database"],
|
|
95
135
|
connect_timeout=self.connection_timeout,
|
|
96
136
|
row_factory=PgDictRowFactory,
|
|
@@ -213,7 +253,7 @@ class PgsqlAsync(DatabaseBackend):
|
|
|
213
253
|
port=self.config["port"],
|
|
214
254
|
sslmode=self.config["ssl"],
|
|
215
255
|
user=self.config["username"],
|
|
216
|
-
password=self.config["password"],
|
|
256
|
+
password=await _resolve_password_async(self.config["password"]),
|
|
217
257
|
dbname=self.config["database"],
|
|
218
258
|
connect_timeout=self.connection_timeout,
|
|
219
259
|
row_factory=PgDictRowFactory,
|
|
@@ -382,15 +422,13 @@ class PgsqlWithPooling(DatabaseBackend):
|
|
|
382
422
|
if "pool_kwargs" not in self.config or not self.config["pool_kwargs"]:
|
|
383
423
|
self.config["pool_kwargs"] = {}
|
|
384
424
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
f"&sslmode={self.config['ssl']}"
|
|
391
|
-
)
|
|
425
|
+
password = self.config["password"]
|
|
426
|
+
conninfo: str | Callable[[], str] = self._conninfo
|
|
427
|
+
if not callable(password):
|
|
428
|
+
conninfo = _pool_conninfo(self.config, password, self.connection_timeout, self.name)
|
|
429
|
+
|
|
392
430
|
self.pool = ConnectionPool(
|
|
393
|
-
|
|
431
|
+
conninfo,
|
|
394
432
|
open=False,
|
|
395
433
|
min_size=2,
|
|
396
434
|
max_size=self.config["maxconnections"],
|
|
@@ -407,6 +445,10 @@ class PgsqlWithPooling(DatabaseBackend):
|
|
|
407
445
|
**self.config["pool_kwargs"],
|
|
408
446
|
)
|
|
409
447
|
|
|
448
|
+
def _conninfo(self) -> str:
|
|
449
|
+
password = _resolve_password(self.config["password"])
|
|
450
|
+
return _pool_conninfo(self.config, password, self.connection_timeout, self.name)
|
|
451
|
+
|
|
410
452
|
##################
|
|
411
453
|
### Connection ###
|
|
412
454
|
##################
|
|
@@ -677,15 +719,13 @@ class PgsqlWithPoolingAsync(DatabaseBackend):
|
|
|
677
719
|
if "pool_kwargs" not in self.config or not self.config["pool_kwargs"]:
|
|
678
720
|
self.config["pool_kwargs"] = {}
|
|
679
721
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
f"&sslmode={self.config['ssl']}"
|
|
686
|
-
)
|
|
722
|
+
password = self.config["password"]
|
|
723
|
+
conninfo: str | Callable[[], Awaitable[str]] = self._conninfo
|
|
724
|
+
if not callable(password):
|
|
725
|
+
conninfo = _pool_conninfo(self.config, password, self.connection_timeout, self.name)
|
|
726
|
+
|
|
687
727
|
self.pool_async = AsyncConnectionPool(
|
|
688
|
-
|
|
728
|
+
conninfo,
|
|
689
729
|
open=False,
|
|
690
730
|
min_size=2,
|
|
691
731
|
max_size=self.config["maxconnections"],
|
|
@@ -713,6 +753,10 @@ class PgsqlWithPoolingAsync(DatabaseBackend):
|
|
|
713
753
|
if hasattr(self, "pool_async"):
|
|
714
754
|
del self.pool_async
|
|
715
755
|
|
|
756
|
+
async def _conninfo(self) -> str:
|
|
757
|
+
password = await _resolve_password_async(self.config["password"])
|
|
758
|
+
return _pool_conninfo(self.config, password, self.connection_timeout, self.name)
|
|
759
|
+
|
|
716
760
|
##################
|
|
717
761
|
### Connection ###
|
|
718
762
|
##################
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: database_wrapper_pgsql
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: database_wrapper for PostgreSQL database
|
|
5
5
|
Author-email: Gints Murans <gm@gm.lv>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/4Apps/py_database_wrapper
|
|
8
8
|
Project-URL: Documentation, https://github.com/4Apps/py_database_wrapper
|
|
9
|
-
Project-URL: Changes, https://github.com/4Apps/py_database_wrapper
|
|
9
|
+
Project-URL: Changes, https://github.com/4Apps/py_database_wrapper/blob/master/CHANGELOG.md
|
|
10
10
|
Project-URL: Code, https://github.com/4Apps/py_database_wrapper
|
|
11
11
|
Project-URL: Issue Tracker, https://github.com/4Apps/py_database_wrapper/issues
|
|
12
12
|
Project-URL: Download, https://pypi.org/project/database_wrapper/
|
|
@@ -32,9 +32,9 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
32
32
|
Requires-Python: >=3.8
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
34
|
License-File: LICENSE
|
|
35
|
-
Requires-Dist: database_wrapper==0.
|
|
35
|
+
Requires-Dist: database_wrapper==0.4.1
|
|
36
36
|
Requires-Dist: psycopg[binary]>=3.2.0
|
|
37
|
-
Requires-Dist: psycopg
|
|
37
|
+
Requires-Dist: psycopg-pool>=3.3.0
|
|
38
38
|
Dynamic: license-file
|
|
39
39
|
|
|
40
40
|
# database_wrapper_pgsql
|
|
@@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "database_wrapper_pgsql"
|
|
7
|
-
# Major.minor only; the patch
|
|
7
|
+
# Major.minor only; the patch comes from the release tags, stamped at build time by
|
|
8
8
|
# scripts/set_version.bash. See scripts/version.bash for what the next release is.
|
|
9
|
-
version = "0.
|
|
9
|
+
version = "0.4.1"
|
|
10
10
|
description = "database_wrapper for PostgreSQL database"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.8"
|
|
@@ -34,16 +34,18 @@ classifiers = [
|
|
|
34
34
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
35
35
|
]
|
|
36
36
|
keywords = ["database", "wrapper", "python", "postgresql", "pgsql"]
|
|
37
|
+
# Floors only, no cap: an upper bound binds every project installing this package. Each
|
|
38
|
+
# floor clears all published security advisories; the database_wrapper pin is exact on purpose.
|
|
37
39
|
dependencies = [
|
|
38
|
-
"database_wrapper == 0.
|
|
40
|
+
"database_wrapper == 0.4.1",
|
|
39
41
|
"psycopg[binary] >= 3.2.0",
|
|
40
|
-
"psycopg
|
|
42
|
+
"psycopg-pool >= 3.3.0",
|
|
41
43
|
]
|
|
42
44
|
|
|
43
45
|
[project.urls]
|
|
44
46
|
Homepage = "https://github.com/4Apps/py_database_wrapper"
|
|
45
47
|
Documentation = "https://github.com/4Apps/py_database_wrapper"
|
|
46
|
-
Changes = "https://github.com/4Apps/py_database_wrapper"
|
|
48
|
+
Changes = "https://github.com/4Apps/py_database_wrapper/blob/master/CHANGELOG.md"
|
|
47
49
|
Code = "https://github.com/4Apps/py_database_wrapper"
|
|
48
50
|
"Issue Tracker" = "https://github.com/4Apps/py_database_wrapper/issues"
|
|
49
51
|
Download = "https://pypi.org/project/database_wrapper/"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{database_wrapper_pgsql-0.3.147 → database_wrapper_pgsql-0.4.1}/database_wrapper_pgsql/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|