ecodev-core 0.0.26__py3-none-any.whl → 0.0.28__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 ecodev-core might be problematic. Click here for more details.

ecodev_core/__init__.py CHANGED
@@ -40,6 +40,7 @@ from ecodev_core.db_insertion import get_raw_df
40
40
  from ecodev_core.db_retrieval import count_rows
41
41
  from ecodev_core.db_retrieval import get_rows
42
42
  from ecodev_core.db_retrieval import ServerSideField
43
+ from ecodev_core.email_sender import send_email
43
44
  from ecodev_core.enum_utils import enum_converter
44
45
  from ecodev_core.list_utils import first_or_default
45
46
  from ecodev_core.list_utils import first_transformed_or_default
@@ -84,4 +85,4 @@ __all__ = [
84
85
  'generic_insertion', 'custom_equal', 'is_authorized_user', 'get_method', 'AppActivity',
85
86
  'fastapi_monitor', 'dash_monitor', 'is_monitoring_user', 'get_recent_activities', 'select_user',
86
87
  'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user',
87
- 'datify', 'safe_drop_columns', 'get_value', 'is_null']
88
+ 'datify', 'safe_drop_columns', 'get_value', 'is_null', 'send_email']
@@ -9,9 +9,9 @@ class AuthenticationConfiguration(BaseSettings):
9
9
  """
10
10
  Simple authentication configuration class
11
11
  """
12
- secret_key: str
13
- algorithm: str
14
- access_token_expire_minutes: int
12
+ secret_key: str = ''
13
+ algorithm: str = ''
14
+ access_token_expire_minutes: int = 0
15
15
  model_config = SettingsConfigDict(env_file='.env')
16
16
 
17
17
 
@@ -20,11 +20,11 @@ class DbSettings(BaseSettings):
20
20
  """
21
21
  Settings class used to connect to the postgresql database
22
22
  """
23
- db_host: str
24
- db_port: str
25
- db_name: str
26
- db_username: str
27
- db_password: str
23
+ db_host: str = ''
24
+ db_port: str = ''
25
+ db_name: str = ''
26
+ db_username: str = ''
27
+ db_password: str = ''
28
28
  model_config = SettingsConfigDict(env_file='.env')
29
29
 
30
30
 
@@ -0,0 +1,53 @@
1
+ """
2
+ Module implementing generic email send
3
+ """
4
+ from email.mime.image import MIMEImage
5
+ from email.mime.multipart import MIMEMultipart
6
+ from email.mime.text import MIMEText
7
+ from pathlib import Path
8
+ from smtplib import SMTP
9
+ from ssl import create_default_context
10
+
11
+ from pydantic_settings import BaseSettings
12
+ from pydantic_settings import SettingsConfigDict
13
+
14
+
15
+ class EmailAuth(BaseSettings):
16
+ """
17
+ Simple authentication configuration class
18
+ """
19
+ email_smtp: str = ''
20
+ email_sender: str = ''
21
+ email_password: str = ''
22
+ model_config = SettingsConfigDict(env_file='.env')
23
+
24
+
25
+ EMAIL_AUTH = EmailAuth()
26
+
27
+
28
+ def send_email(email: str, body: str, topic: str, images: dict[str, Path] | None = None) -> None:
29
+ """
30
+ Generic email sender.
31
+
32
+ Attributes are:
33
+ - email: The email to which to send
34
+ - body: the email body
35
+ - topic: the email topic
36
+ - images: if any, the Dict of image tags:image paths to incorporate in the email
37
+ """
38
+ em = MIMEMultipart('related')
39
+ em['From'] = EMAIL_AUTH.email_sender
40
+ em['To'] = email
41
+ em['Subject'] = topic
42
+ em.attach(MIMEText(body, 'html'))
43
+ for tag, img_path in (images or {}).items():
44
+ with open(img_path, 'rb') as fp:
45
+ img = MIMEImage(fp.read())
46
+ img.add_header('Content-ID', f'<{tag}>')
47
+ em.attach(img)
48
+
49
+ with SMTP(EMAIL_AUTH.email_smtp, 587) as server:
50
+ server.ehlo()
51
+ server.starttls(context=create_default_context())
52
+ server.login(EMAIL_AUTH.email_sender, EMAIL_AUTH.email_password)
53
+ server.sendmail(EMAIL_AUTH.email_sender, email, em.as_string())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ecodev-core
3
- Version: 0.0.26
3
+ Version: 0.0.28
4
4
  Summary: Low level sqlmodel/fastapi/pydantic building blocks
5
5
  License: MIT
6
6
  Author: Thomas Epelbaum
@@ -1,16 +1,17 @@
1
- ecodev_core/__init__.py,sha256=JVtBxh-CIZQODjq4tHhl3o1qK1DqMJQsbtlFXjXBuYY,4690
1
+ ecodev_core/__init__.py,sha256=UfdudadIclGQH_twdS5-spE-1g7SNDAo1XFDzjE24NU,4752
2
2
  ecodev_core/app_activity.py,sha256=_rU5uPfttHxXX5IaCuTA7K9We5w2qluJ3Xpf6i12HhY,3763
3
3
  ecodev_core/app_rights.py,sha256=RZPdDtydFqc_nFj96huKAc56BS0qS6ScKv4Kghqd6lc,726
4
4
  ecodev_core/app_user.py,sha256=r1bqA4H08x53XmxmjwyGKl_PFjYQazzBbVErdkztqeE,2947
5
- ecodev_core/auth_configuration.py,sha256=ZjEB-N5HTo2jaEljwrh6q64Lh5qZ1NuKk8bbpIEcdYc,433
5
+ ecodev_core/auth_configuration.py,sha256=R8XH674J1HQSxMr-abvrG0zRqANRf07eMLiG4yB04gM,447
6
6
  ecodev_core/authentication.py,sha256=aLMk2_fn1Fodrby2ywZraB3JTSsSrPsBiQq0ag0ySiY,10023
7
7
  ecodev_core/backup.py,sha256=8fwBHic6hE8swNESIayZqqWZFHFz5f-puBWSt5f_ZLw,3119
8
8
  ecodev_core/check_dependencies.py,sha256=aFn8GI4eBbuJT8RxsfhSSnlpNYYj_LPOH-tZF0EqfKQ,6917
9
9
  ecodev_core/custom_equal.py,sha256=2gRn0qpyJ8-Kw9GQSueu0nLngLrRrwyMPlP6zqPac0U,899
10
- ecodev_core/db_connection.py,sha256=ha2YVVQQwQ5WCyrUnaKq4LSaXoPGGbh19xKRbr438U8,1773
10
+ ecodev_core/db_connection.py,sha256=qRcs0MjLFfhO7pnSof1l1m1BbPqYfEsUlMQkKT9fn_4,1798
11
11
  ecodev_core/db_filters.py,sha256=T_5JVF27UEu7sC6NOm7-W3_Y0GLfbWQO_EeTXcD2cv8,5041
12
12
  ecodev_core/db_insertion.py,sha256=RSCyAlUObbBlWJuMRX-YFY4VgtWqYLdwRqMWw--x95Y,3646
13
13
  ecodev_core/db_retrieval.py,sha256=IxyF3ZtKgACLiNFggK7boKggvMRKYDRD2IimxU4dap4,7345
14
+ ecodev_core/email_sender.py,sha256=XD7jAVXhGzvbiHqMhK9_aTEIS70Lw_CmPeAxRZGji-Y,1610
14
15
  ecodev_core/enum_utils.py,sha256=BkQ4YQ97tXBYmMcQiSIi0mbioD5CgVU79myg1BBAXuA,556
15
16
  ecodev_core/list_utils.py,sha256=Vyws12Jv0CLdQiQl1ym0z7E6-LJTLholYHZySQxYwhM,3006
16
17
  ecodev_core/logger.py,sha256=AWGGNZz12Ql0JDq1wCJQxwxK2syiczEBftmuJkjbAPw,3149
@@ -19,7 +20,7 @@ ecodev_core/permissions.py,sha256=WAx-ilMu8LlQp2sjJVdkhNQieytEaEm8577ZF1HWeTY,50
19
20
  ecodev_core/pydantic_utils.py,sha256=e3GH50JmcpTmd2UgrB94QSwWOlOCW3WIlVdyX9C4T-U,741
20
21
  ecodev_core/read_write.py,sha256=auJ5bBJTVGkLRkiP_vZxVCX64B0Y-9qpsaDhovHmbas,996
21
22
  ecodev_core/safe_utils.py,sha256=JCfxo6fcznjsL-XHNJ1TKo1UvfJB83WT5jpTFmtJwsE,6160
22
- ecodev_core-0.0.26.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
23
- ecodev_core-0.0.26.dist-info/METADATA,sha256=uBVogQUbridd3IvVfepy8spgLb-EHl_Osmo_Wde9Kfo,3276
24
- ecodev_core-0.0.26.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
25
- ecodev_core-0.0.26.dist-info/RECORD,,
23
+ ecodev_core-0.0.28.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
24
+ ecodev_core-0.0.28.dist-info/METADATA,sha256=697bq6i2muEH-kNus4dezXvSiDJSKy1OVdpv6Qj8Fjk,3276
25
+ ecodev_core-0.0.28.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
26
+ ecodev_core-0.0.28.dist-info/RECORD,,