archipy-postgres 5.24.0__tar.gz → 5.26.0__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.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: archipy-postgres
3
- Version: 5.24.0
3
+ Version: 5.26.0
4
4
  Summary: ArchiPy postgres adapter.
5
5
  Author-email: Hossein Nejati <hosseinnejati14@gmail.com>
6
6
  License-Expression: Apache-2.0
7
7
  Requires-Python: <4,>=3.14
8
- Requires-Dist: archipy==5.24.0
8
+ Requires-Dist: archipy==5.26.0
9
9
  Requires-Dist: psycopg[binary]>=3.3.6
10
10
  Description-Content-Type: text/markdown
11
11
 
@@ -15,6 +15,48 @@ from archipy.helpers.metaclasses.singleton import Singleton
15
15
  from archipy.models.errors import DatabaseConnectionError
16
16
 
17
17
 
18
+ def _build_connect_args(configs: PostgresSQLAlchemyConfig) -> dict[str, Any]:
19
+ """Build the psycopg connection arguments from the configuration.
20
+
21
+ Args:
22
+ configs: PostgreSQL configuration.
23
+
24
+ Returns:
25
+ dict[str, Any]: Only the options that are configured (libpq defaults apply to the rest).
26
+ """
27
+ candidates = {
28
+ "connect_timeout": configs.CONNECT_TIMEOUT,
29
+ "sslmode": configs.SSL_MODE,
30
+ "sslrootcert": configs.SSL_ROOT_CERT,
31
+ "sslcert": configs.SSL_CERT,
32
+ "sslkey": configs.SSL_KEY,
33
+ "application_name": configs.APPLICATION_NAME,
34
+ "options": _build_server_options(configs),
35
+ "prepare_threshold": configs.PREPARE_THRESHOLD,
36
+ }
37
+ connect_args: dict[str, Any] = {name: value for name, value in candidates.items() if value is not None}
38
+ if configs.DISABLE_PREPARED_STATEMENTS:
39
+ connect_args["prepare_threshold"] = None # psycopg: None never prepares
40
+ return connect_args
41
+
42
+
43
+ def _build_server_options(configs: PostgresSQLAlchemyConfig) -> str | None:
44
+ """Build the libpq ``options`` string that sets the session timeouts.
45
+
46
+ Args:
47
+ configs: PostgreSQL configuration.
48
+
49
+ Returns:
50
+ str | None: e.g. ``-c statement_timeout=5000 -c lock_timeout=1000``, or None when neither is set.
51
+ """
52
+ settings = {
53
+ "statement_timeout": configs.STATEMENT_TIMEOUT_MS,
54
+ "lock_timeout": configs.LOCK_TIMEOUT_MS,
55
+ }
56
+ options = [f"-c {name}={value}" for name, value in settings.items() if value is not None]
57
+ return " ".join(options) or None
58
+
59
+
18
60
  class PostgresSQlAlchemySessionManager(BaseSQLAlchemySessionManager[PostgresSQLAlchemyConfig], metaclass=Singleton):
19
61
  """Synchronous SQLAlchemy session manager for PostgreSQL.
20
62
 
@@ -64,9 +106,9 @@ class PostgresSQlAlchemySessionManager(BaseSQLAlchemySessionManager[PostgresSQLA
64
106
  """Return the psycopg connection arguments.
65
107
 
66
108
  Returns:
67
- dict[str, Any]: ``connect_timeout`` when configured, otherwise empty (libpq waits indefinitely).
109
+ dict[str, Any]: The configured connect timeout, TLS, application name, session timeout and prepare options.
68
110
  """
69
- return {} if self._configs.CONNECT_TIMEOUT is None else {"connect_timeout": self._configs.CONNECT_TIMEOUT}
111
+ return _build_connect_args(self._configs)
70
112
 
71
113
  @override
72
114
  def _create_url(self, configs: PostgresSQLAlchemyConfig) -> URL:
@@ -85,7 +127,7 @@ class PostgresSQlAlchemySessionManager(BaseSQLAlchemySessionManager[PostgresSQLA
85
127
  return URL.create(
86
128
  drivername=configs.DRIVER_NAME,
87
129
  username=configs.USERNAME,
88
- password=configs.PASSWORD,
130
+ password=configs.PASSWORD.get_secret_value() if configs.PASSWORD else None,
89
131
  host=configs.HOST,
90
132
  port=configs.PORT,
91
133
  database=configs.DATABASE,
@@ -148,9 +190,9 @@ class AsyncPostgresSQlAlchemySessionManager(
148
190
  """Return the psycopg connection arguments.
149
191
 
150
192
  Returns:
151
- dict[str, Any]: ``connect_timeout`` when configured, otherwise empty (libpq waits indefinitely).
193
+ dict[str, Any]: The configured connect timeout, TLS, application name, session timeout and prepare options.
152
194
  """
153
- return {} if self._configs.CONNECT_TIMEOUT is None else {"connect_timeout": self._configs.CONNECT_TIMEOUT}
195
+ return _build_connect_args(self._configs)
154
196
 
155
197
  @override
156
198
  def _create_url(self, configs: PostgresSQLAlchemyConfig) -> URL:
@@ -169,7 +211,7 @@ class AsyncPostgresSQlAlchemySessionManager(
169
211
  return URL.create(
170
212
  drivername=configs.DRIVER_NAME,
171
213
  username=configs.USERNAME,
172
- password=configs.PASSWORD,
214
+ password=configs.PASSWORD.get_secret_value() if configs.PASSWORD else None,
173
215
  host=configs.HOST,
174
216
  port=configs.PORT,
175
217
  database=configs.DATABASE,
@@ -5,10 +5,10 @@ authors = [
5
5
  { name = "Hossein Nejati", email = "hosseinnejati14@gmail.com" },
6
6
  ]
7
7
  readme = "README.md"
8
- version = "5.24.0" # This version is set on publish flow!
8
+ version = "5.26.0" # This version is set on publish flow!
9
9
  requires-python = ">=3.14,<4"
10
10
  dependencies = [
11
- "archipy==5.24.0", # Pinned to core version on publish flow!
11
+ "archipy==5.26.0", # Pinned to core version on publish flow!
12
12
  "psycopg[binary]>=3.3.6",
13
13
  ]
14
14
  license = "Apache-2.0"