altcodepro-polydb-python 2.3.14__tar.gz → 2.3.15__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.
Files changed (83) hide show
  1. {altcodepro_polydb_python-2.3.14/src/altcodepro_polydb_python.egg-info → altcodepro_polydb_python-2.3.15}/PKG-INFO +1 -1
  2. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/pyproject.toml +1 -1
  3. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15/src/altcodepro_polydb_python.egg-info}/PKG-INFO +1 -1
  4. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/PostgreSQLAdapter.py +54 -5
  5. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/LICENSE +0 -0
  6. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/MANIFEST.in +0 -0
  7. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/README.md +0 -0
  8. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/requirements-aws.txt +0 -0
  9. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/requirements-azure.txt +0 -0
  10. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/requirements-dev.txt +0 -0
  11. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/requirements-gcp.txt +0 -0
  12. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/requirements-generic.txt +0 -0
  13. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/requirements.txt +0 -0
  14. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/setup.cfg +0 -0
  15. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/setup.py +0 -0
  16. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/altcodepro_polydb_python.egg-info/SOURCES.txt +0 -0
  17. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/altcodepro_polydb_python.egg-info/dependency_links.txt +0 -0
  18. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/altcodepro_polydb_python.egg-info/requires.txt +0 -0
  19. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/altcodepro_polydb_python.egg-info/top_level.txt +0 -0
  20. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/PolyDB.py +0 -0
  21. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/__init__.py +0 -0
  22. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/AzureBlobStorageAdapter.py +0 -0
  23. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/AzureFileStorageAdapter.py +0 -0
  24. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/AzureQueueAdapter.py +0 -0
  25. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/AzureTableStorageAdapter.py +0 -0
  26. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/BlockchainBlobAdapter.py +0 -0
  27. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/BlockchainFileAdapter.py +0 -0
  28. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/BlockchainKVAdapter.py +0 -0
  29. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/BlockchainQueueAdapter.py +0 -0
  30. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/DynamoDBAdapter.py +0 -0
  31. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/EFSAdapter.py +0 -0
  32. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/FirestoreAdapter.py +0 -0
  33. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/GCPFilestoreAdapter.py +0 -0
  34. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/GCPPubSubAdapter.py +0 -0
  35. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/GCPStorageAdapter.py +0 -0
  36. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/MongoDBAdapter.py +0 -0
  37. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/S3Adapter.py +0 -0
  38. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/S3CompatibleAdapter.py +0 -0
  39. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/SQSAdapter.py +0 -0
  40. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/VercelBlobAdapter.py +0 -0
  41. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/VercelFileAdapter.py +0 -0
  42. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/VercelKVAdapter.py +0 -0
  43. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/VercelQueueAdapter.py +0 -0
  44. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/adapters/__init__.py +0 -0
  45. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/advanced_query.py +0 -0
  46. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/audit/AuditStorage.py +0 -0
  47. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/audit/__init__.py +0 -0
  48. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/audit/context.py +0 -0
  49. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/audit/manager.py +0 -0
  50. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/audit/models.py +0 -0
  51. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/base/NoSQLKVAdapter.py +0 -0
  52. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/base/ObjectStorageAdapter.py +0 -0
  53. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/base/QueueAdapter.py +0 -0
  54. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/base/SharedFilesAdapter.py +0 -0
  55. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/base/__init__.py +0 -0
  56. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/batch.py +0 -0
  57. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/cache.py +0 -0
  58. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/cloudDatabaseFactory.py +0 -0
  59. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/databaseFactory.py +0 -0
  60. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/decorators.py +0 -0
  61. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/errors.py +0 -0
  62. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/json_safe.py +0 -0
  63. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/models.py +0 -0
  64. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/monitoring.py +0 -0
  65. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/multitenancy.py +0 -0
  66. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/py.typed +0 -0
  67. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/query.py +0 -0
  68. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/registry.py +0 -0
  69. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/retry.py +0 -0
  70. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/schema.py +0 -0
  71. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/security.py +0 -0
  72. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/types.py +0 -0
  73. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/utils.py +0 -0
  74. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/src/polydb/validation.py +0 -0
  75. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_aws.py +0 -0
  76. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_azure.py +0 -0
  77. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_blockchain.py +0 -0
  78. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_cloud_factory.py +0 -0
  79. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_gcp.py +0 -0
  80. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_mongodb.py +0 -0
  81. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_multi_engine.py +0 -0
  82. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_postgresql.py +0 -0
  83. {altcodepro_polydb_python-2.3.14 → altcodepro_polydb_python-2.3.15}/tests/test_vercel.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: altcodepro-polydb-python
3
- Version: 2.3.14
3
+ Version: 2.3.15
4
4
  Summary: Production-ready multi-cloud database abstraction layer with connection pooling, retry logic, and thread safety
5
5
  Author: AltCodePro
6
6
  Project-URL: Homepage, https://github.com/altcodepro/polydb-python
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "altcodepro-polydb-python"
7
- version = "2.3.14"
7
+ version = "2.3.15"
8
8
  description = "Production-ready multi-cloud database abstraction layer with connection pooling, retry logic, and thread safety"
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: altcodepro-polydb-python
3
- Version: 2.3.14
3
+ Version: 2.3.15
4
4
  Summary: Production-ready multi-cloud database abstraction layer with connection pooling, retry logic, and thread safety
5
5
  Author: AltCodePro
6
6
  Project-URL: Homepage, https://github.com/altcodepro/polydb-python
@@ -32,25 +32,64 @@ class PostgreSQLAdapter:
32
32
  self._lock = threading.Lock()
33
33
  self._initialize_pool()
34
34
 
35
+ def _ping_connection(self, conn) -> bool:
36
+ """Test if connection is still alive"""
37
+ try:
38
+ with conn.cursor() as cur:
39
+ cur.execute("SELECT 1")
40
+ return True
41
+ except Exception:
42
+ return False
43
+
35
44
  def _initialize_pool(self):
36
45
  try:
37
46
  import psycopg2.pool
47
+ from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
48
+
49
+ # Enhance connection string with better Azure settings
50
+ dsn = self.connection_string
51
+ if "postgresql://" in dsn:
52
+ parsed = urlparse(dsn)
53
+ query = parse_qs(parsed.query)
54
+ query.setdefault("connect_timeout", ["30"])
55
+ query.setdefault("keepalives", ["1"])
56
+ query.setdefault("keepalives_idle", ["30"])
57
+ query.setdefault("keepalives_interval", ["10"])
58
+ query.setdefault("keepalives_count", ["5"])
59
+
60
+ new_query = urlencode(query, doseq=True)
61
+ parsed = parsed._replace(query=new_query)
62
+ dsn = urlunparse(parsed)
38
63
 
39
64
  with self._lock:
40
65
  if not self._pool:
41
66
  self._pool = psycopg2.pool.ThreadedConnectionPool(
42
- minconn=int(os.getenv("POSTGRES_MIN_CONNECTIONS", "2")),
43
- maxconn=int(os.getenv("POSTGRES_MAX_CONNECTIONS", "20")),
44
- dsn=self.connection_string,
67
+ minconn=int(os.getenv("POSTGRES_MIN_CONNECTIONS", "5")),
68
+ maxconn=int(os.getenv("POSTGRES_MAX_CONNECTIONS", "30")),
69
+ dsn=dsn,
45
70
  )
46
- self.logger.info("PostgreSQL pool initialized")
71
+ self.logger.info("PostgreSQL pool initialized with Azure optimizations")
47
72
  except Exception as e:
48
73
  raise ConnectionError(f"Failed to initialize PostgreSQL pool: {str(e)}")
49
74
 
50
75
  def _get_connection(self) -> Any:
51
76
  if not self._pool:
52
77
  self._initialize_pool()
53
- return self._pool.getconn() # type: ignore
78
+
79
+ try:
80
+ conn = self._pool.getconn() # type: ignore
81
+
82
+ # Critical: Validate connection for Azure transient issues
83
+ if not self._ping_connection(conn):
84
+ self.logger.warning("Stale connection detected from pool, closing and retrying")
85
+ self._pool.putconn(conn, close=True) # type: ignore
86
+ conn = self._pool.getconn() # type: ignore # Get fresh connection
87
+
88
+ return conn
89
+
90
+ except Exception as e:
91
+ self.logger.error(f"Failed to acquire connection from pool: {e}")
92
+ raise ConnectionError(f"Could not obtain database connection: {e}") from e
54
93
 
55
94
  def _return_connection(self, conn: Any):
56
95
  if self._pool and conn:
@@ -59,6 +98,16 @@ class PostgreSQLAdapter:
59
98
  # ---------------------------------------------------------------------
60
99
  # TRANSACTIONS
61
100
  # ---------------------------------------------------------------------
101
+ def reset_pool(self):
102
+ """Reset the entire pool (call during startup or after major failures)"""
103
+ with self._lock:
104
+ if self._pool:
105
+ try:
106
+ self._pool.closeall()
107
+ except:
108
+ pass
109
+ self._pool = None
110
+ self._initialize_pool()
62
111
 
63
112
  def begin_transaction(self) -> Any:
64
113
  """Begin a transaction and return the connection handle."""