lecrapaud 0.18.8__py3-none-any.whl → 0.18.10__py3-none-any.whl

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.

Potentially problematic release.


This version of lecrapaud might be problematic. Click here for more details.

@@ -14,16 +14,20 @@ from lecrapaud.config import LECRAPAUD_TABLE_PREFIX
14
14
 
15
15
 
16
16
  def with_db(func):
17
- """Decorator to allow passing an optional db session"""
18
-
17
+ """Decorator to provide a database session to the wrapped function.
18
+
19
+ If a db parameter is already provided, it will be used. Otherwise,
20
+ a new session will be created and automatically managed.
21
+ """
19
22
  @wraps(func)
20
23
  def wrapper(*args, **kwargs):
21
- db = kwargs.pop("db", None)
22
- if db:
23
- return func(*args, db=db, **kwargs)
24
+ if "db" in kwargs and kwargs["db"] is not None:
25
+ return func(*args, **kwargs)
26
+
24
27
  with get_db() as db:
25
- return func(*args, db=db, **kwargs)
26
-
28
+ kwargs["db"] = db
29
+ return func(*args, **kwargs)
30
+
27
31
  return wrapper
28
32
 
29
33
 
lecrapaud/db/session.py CHANGED
@@ -12,6 +12,7 @@ from lecrapaud.config import DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME, DB
12
12
 
13
13
  _engine = None
14
14
  _SessionLocal = None
15
+
15
16
  if DB_URI:
16
17
  if "mysql://" in DB_URI and "pymysql://" not in DB_URI:
17
18
  DB_URI = DB_URI.replace("mysql://", "mysql+pymysql://")
@@ -53,11 +54,26 @@ def init_db(uri: str = None):
53
54
  conn.execute(text(f"CREATE DATABASE IF NOT EXISTS `{db_name}`"))
54
55
  conn.commit()
55
56
 
56
- # Step 3: Connect to the newly created database
57
- _engine = create_engine(DATABASE_URL, echo=False)
57
+ # Step 3: Configure main engine with connection pooling and reconnection settings
58
+ _engine = create_engine(
59
+ DATABASE_URL,
60
+ echo=False,
61
+ pool_pre_ping=True, # Check connection health before using
62
+ pool_recycle=3600, # Recycle connections after 1 hour
63
+ pool_timeout=30, # Wait 30 seconds for a connection from the pool
64
+ pool_size=10, # Maintain up to 10 connections
65
+ max_overflow=10, # Allow up to 10 more connections during spikes
66
+ connect_args={
67
+ "connect_timeout": 10, # 10 second connection timeout
68
+ },
69
+ )
58
70
 
59
- # Step 4: Create session factory
60
- _SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=_engine)
71
+ # Step 4: Configure session factory
72
+ _SessionLocal = sessionmaker(
73
+ autocommit=False,
74
+ autoflush=False,
75
+ bind=_engine,
76
+ )
61
77
 
62
78
  # Step 5: Apply Alembic migrations programmatically
63
79
  current_dir = os.path.dirname(__file__) # → lecrapaud/db
@@ -76,8 +92,17 @@ def init_db(uri: str = None):
76
92
  # Dependency to get a session instance
77
93
  @contextmanager
78
94
  def get_db():
95
+ """Get a database session with automatic connection management.
96
+
97
+ Yields:
98
+ Session: A SQLAlchemy session instance
99
+
100
+ The session is automatically committed if no exceptions occur, and rolled back otherwise.
101
+ The connection is automatically returned to the pool when the session is closed.
102
+ """
79
103
  if _SessionLocal is None:
80
104
  init_db()
105
+
81
106
  db = _SessionLocal()
82
107
  try:
83
108
  yield db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lecrapaud
3
- Version: 0.18.8
3
+ Version: 0.18.10
4
4
  Summary: Framework for machine and deep learning, with regression, classification and time series analysis
5
5
  License: Apache License
6
6
  Author: Pierre H. Gallet
@@ -12,7 +12,7 @@ lecrapaud/db/alembic/versions/2025_06_25_1759-72aa496ca65b_.py,sha256=MiqooJuZ1e
12
12
  lecrapaud/db/alembic/versions/2025_08_25_1434-7ed9963e732f_add_best_score_to_model_selection.py,sha256=gyQDFFHp1dlILuDtXSPdUU_MsLlX-UzTP-E96Aj_Hto,966
13
13
  lecrapaud/db/alembic.ini,sha256=Zw2rdwsKV6c7J1SPtoFIPDX08_oTP3MuUKnNxBDiY8I,3796
14
14
  lecrapaud/db/models/__init__.py,sha256=Lhyw9fVLdom0Fc6yIP-ip8FjkU1EwVwjae5q2VM815Q,740
15
- lecrapaud/db/models/base.py,sha256=J9ew-0z_-tnWAwhVvOmVDys2R6jPF_oSca_ny6wpXQE,7606
15
+ lecrapaud/db/models/base.py,sha256=Sc6g38LsNsjn9-qpWOMSsZlbUER0Xr56-yLIJLpTMDU,7808
16
16
  lecrapaud/db/models/experiment.py,sha256=LjsMTY-PA9HZ27D2sz2fWy7HvwFqiS0dXKaiKF-S3k4,14868
17
17
  lecrapaud/db/models/feature.py,sha256=5o77O2FyRObnLOCGNj8kaPSGM3pLv1Ov6mXXHYkmnYY,1136
18
18
  lecrapaud/db/models/feature_selection.py,sha256=mk42xuw1Sm_7Pznfg7TNc5_S4hscdw79QgIe3Bt9ZRI,3245
@@ -23,7 +23,7 @@ lecrapaud/db/models/model_training.py,sha256=jAIYPdwBln2jf593soLQ730uYrTfNK8zdG8
23
23
  lecrapaud/db/models/score.py,sha256=fSfXLt6Dm-8Fy9ku0urMT5Fa6zNqn4YqVnEO4o3zKVI,1669
24
24
  lecrapaud/db/models/target.py,sha256=DKnfeaLU8eT8J_oh_vuFo5-o1CaoXR13xBbswme6Bgk,1649
25
25
  lecrapaud/db/models/utils.py,sha256=-a-nWWmpJ2XzidIxo2COVUTrGZIPYCfBzjhcszJj_bM,1109
26
- lecrapaud/db/session.py,sha256=E93WXcFFILFAIeH61ft2Egs7D-6caqs0oi4zCkO5Lq4,2822
26
+ lecrapaud/db/session.py,sha256=87W5AkGRYu8b2rF5FNQ0MFC6wtGc-gGagNJQN_0vnDQ,3667
27
27
  lecrapaud/directories.py,sha256=0LrANuDgbuneSLker60c6q2hmGnQ3mKHIztTGzTx6Gw,826
28
28
  lecrapaud/experiment.py,sha256=1xLWjOrqAxJh9CdXOx9ppQuRFRRj0GH-xYZqg-ty9hI,2463
29
29
  lecrapaud/feature_engineering.py,sha256=ib1afBrwqePiXUaw0Cpe6hY3VNl5afg8YVntb88SCT4,39199
@@ -40,7 +40,7 @@ lecrapaud/misc/test-gpu-transformers.ipynb,sha256=k6MBSs_Um1h4PykvE-LTBcdpbWLbIF
40
40
  lecrapaud/model_selection.py,sha256=gP7Jo_JyI7YVKNk7VG5DjGcheUZsir1vNnTlTCM-R40,72480
41
41
  lecrapaud/search_space.py,sha256=-JkzuMhaomdwiWi4HvVQY5hiw3-oREemJA16tbwEIp4,34854
42
42
  lecrapaud/utils.py,sha256=ATKu9pbXjYFRa2YzBYjqyLHJrzfnZ7SJrOD_qAnEBYE,8242
43
- lecrapaud-0.18.8.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
44
- lecrapaud-0.18.8.dist-info/METADATA,sha256=YPdQBTq3CnTlpO0CtvoST5Ywn0PwbplPNoIIHPXRdvE,11081
45
- lecrapaud-0.18.8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
- lecrapaud-0.18.8.dist-info/RECORD,,
43
+ lecrapaud-0.18.10.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
44
+ lecrapaud-0.18.10.dist-info/METADATA,sha256=sNtSCq48-BMA7lyHaddo0hdVe5_24969ZqD_Sb_6iIw,11082
45
+ lecrapaud-0.18.10.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
+ lecrapaud-0.18.10.dist-info/RECORD,,