dwyeapi 0.7.0__tar.gz → 0.7.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.
Files changed (60) hide show
  1. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/PKG-INFO +1 -1
  2. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/pyproject.toml +1 -1
  3. dwyeapi-0.7.1/src/dwyeapi/config.py +141 -0
  4. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi.egg-info/PKG-INFO +1 -1
  5. dwyeapi-0.7.0/src/dwyeapi/config.py +0 -90
  6. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/README.md +0 -0
  7. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/setup.cfg +0 -0
  8. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/__init__.py +0 -0
  9. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/cache.py +0 -0
  10. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/database.py +0 -0
  11. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/dependencies.py +0 -0
  12. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/dt.py +0 -0
  13. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/exceptions.py +0 -0
  14. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/health.py +0 -0
  15. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/logger.py +0 -0
  16. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/masking.py +0 -0
  17. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/pagination.py +0 -0
  18. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/__init__.py +0 -0
  19. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/__init__.py +0 -0
  20. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/aliyun.py +0 -0
  21. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/base.py +0 -0
  22. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/config.py +0 -0
  23. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/factory.py +0 -0
  24. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/mock.py +0 -0
  25. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/protocol.py +0 -0
  26. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/email/resend.py +0 -0
  27. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/__init__.py +0 -0
  28. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/aliyun.py +0 -0
  29. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/base.py +0 -0
  30. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/config.py +0 -0
  31. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/factory.py +0 -0
  32. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/mock.py +0 -0
  33. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/providers/sms/protocol.py +0 -0
  34. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/response.py +0 -0
  35. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/security.py +0 -0
  36. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/__init__.py +0 -0
  37. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/context.py +0 -0
  38. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/model.py +0 -0
  39. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/pool.py +0 -0
  40. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/registry.py +0 -0
  41. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/router.py +0 -0
  42. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/schema.py +0 -0
  43. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/service.py +0 -0
  44. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi/tasks/worker.py +0 -0
  45. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi.egg-info/SOURCES.txt +0 -0
  46. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi.egg-info/dependency_links.txt +0 -0
  47. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi.egg-info/requires.txt +0 -0
  48. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/src/dwyeapi.egg-info/top_level.txt +0 -0
  49. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_cache.py +0 -0
  50. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_config.py +0 -0
  51. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_database.py +0 -0
  52. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_dependencies.py +0 -0
  53. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_exceptions.py +0 -0
  54. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_health.py +0 -0
  55. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_logger.py +0 -0
  56. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_masking.py +0 -0
  57. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_pagination.py +0 -0
  58. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_response.py +0 -0
  59. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_security.py +0 -0
  60. {dwyeapi-0.7.0 → dwyeapi-0.7.1}/tests/test_tasks.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dwyeapi
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary: Lightweight FastAPI infrastructure — exceptions, database, config, security, cache, pagination, logger
5
5
  License: MIT
6
6
  Requires-Python: >=3.11
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dwyeapi"
3
- version = "0.7.0"
3
+ version = "0.7.1"
4
4
  description = "Lightweight FastAPI infrastructure — exceptions, database, config, security, cache, pagination, logger"
5
5
  requires-python = ">=3.11"
6
6
  license = {text = "MIT"}
@@ -0,0 +1,141 @@
1
+ """FastAPI 项目通用 Pydantic Settings 基类。
2
+
3
+ 除了 database_url / redis_url / secret_key 等基础字段外,还提供运行环境识别 API:
4
+
5
+ - ``environment`` 字段: ``"dev"`` | ``"prod"``,默认 ``"prod"``(误配置时偏保守)
6
+ - ``get_environment()`` / ``is_dev()`` / ``is_prod()``:业务代码读取当前环境
7
+
8
+ 业务项目实例化 ``Settings()`` 时会自动把 environment 值写入模块级全局变量,
9
+ 之后任何地方 import 即可读,避免把 Settings 实例到处传递。
10
+ """
11
+
12
+ from typing import Literal
13
+
14
+ from pydantic import Field, model_validator
15
+ from pydantic_settings import BaseSettings as PydanticBaseSettings
16
+ from pydantic_settings import SettingsConfigDict
17
+
18
+ Environment = Literal["dev", "prod"]
19
+
20
+ _current_environment: Environment = "prod"
21
+
22
+
23
+ def get_environment() -> Environment:
24
+ """返回当前运行环境。
25
+
26
+ 未实例化 Settings 前默认返回 ``"prod"`` (保守),业务 ``Settings()`` 加载
27
+ 后会同步为配置值。
28
+ """
29
+ return _current_environment
30
+
31
+
32
+ def is_dev() -> bool:
33
+ """当前是否为开发环境。"""
34
+ return _current_environment == "dev"
35
+
36
+
37
+ def is_prod() -> bool:
38
+ """当前是否为生产环境。"""
39
+ return _current_environment == "prod"
40
+
41
+
42
+ def set_current_environment(env: Environment) -> None:
43
+ """内部使用: 由 BaseSettings 校验钩子或测试显式切换时调用。"""
44
+ global _current_environment
45
+ _current_environment = env
46
+
47
+
48
+ class BaseSettings(PydanticBaseSettings):
49
+ """FastAPI 项目共用的配置基类。
50
+
51
+ 业务项目通过继承并追加项目专属字段使用,内置的 database_url / redis_url /
52
+ secret_key 等字段覆盖最常用的基础设施需求,不需要每个项目重复声明。
53
+ 配置来源默认为 ``.env`` 文件,嵌套字段使用双下划线 ``__`` 分隔。
54
+ """
55
+
56
+ database_url: str = Field(
57
+ description="数据库连接串(异步驱动),例 postgresql+asyncpg://user:pass@host:5432/db",
58
+ )
59
+ redis_url: str = Field(
60
+ description="Redis 连接串,例 redis://localhost:6379/0",
61
+ )
62
+ secret_key: str = Field(
63
+ description="应用密钥,用于 JWT 签名与敏感数据加密,至少 32 位随机字符串",
64
+ )
65
+ jwt_algorithm: str = Field(
66
+ default="HS256",
67
+ description="JWT 签名算法,默认 HS256",
68
+ )
69
+ access_token_expire_minutes: int = Field(
70
+ default=30,
71
+ description="JWT access token 有效期(分钟),默认 30 分钟",
72
+ )
73
+ environment: Environment = Field(
74
+ default="prod",
75
+ description='运行环境,"dev" 开启调试特性 / 允许 mock providers,"prod" 关闭调试并禁用 mock',
76
+ )
77
+ allowed_origins: list[str] = Field(
78
+ default_factory=list,
79
+ description="CORS 允许的来源域名列表,生产环境禁止使用 ['*']",
80
+ )
81
+
82
+ # ── 异步任务配置(task_ 前缀)──
83
+ task_max_jobs: int = Field(
84
+ default=5,
85
+ description="ARQ worker 并发执行的最大任务数",
86
+ )
87
+ task_job_timeout: int = Field(
88
+ default=3600,
89
+ description="单个任务执行超时(秒),超时后被中止,默认 1 小时",
90
+ )
91
+ task_failure_ttl: int = Field(
92
+ default=86400,
93
+ description="失败任务结果在 Redis 中的保留时长(秒),默认 1 天",
94
+ )
95
+
96
+ # ── 日志配置(log_ 前缀)──
97
+ log_level: str = Field(
98
+ default="INFO",
99
+ description="最低日志级别:DEBUG / INFO / WARNING / ERROR / CRITICAL",
100
+ )
101
+ log_dir: str | None = Field(
102
+ default=".",
103
+ description='日志文件目录,默认 "." 即进程当前目录;显式设为 None 可关闭文件输出(仅控制台)',
104
+ )
105
+ log_filename: str = Field(
106
+ default="app",
107
+ description="日志文件基础名,最终文件形如 {filename}_YYYY-MM-DD.log",
108
+ )
109
+ log_max_bytes: int = Field(
110
+ default=100 * 1024 * 1024,
111
+ description="单个日志文件大小上限(字节),超出后滚动,默认 100 MB",
112
+ )
113
+ log_retention: str = Field(
114
+ default="30 days",
115
+ description='日志保留策略,loguru 语法,例 "30 days" / "1 week" / 整数个数',
116
+ )
117
+ log_console: bool = Field(
118
+ default=True,
119
+ description="是否输出带颜色的日志到 stderr 控制台",
120
+ )
121
+ log_serialize: bool = Field(
122
+ default=False,
123
+ description="文件 sink 是否按 JSON Lines 序列化,便于日志聚合系统解析",
124
+ )
125
+ log_intercept_stdlib: bool = Field(
126
+ default=True,
127
+ description="是否拦截 stdlib logging,让 uvicorn / SQLAlchemy / httpx 等共享同一套 sink",
128
+ )
129
+
130
+ model_config = SettingsConfigDict(
131
+ env_file=".env",
132
+ env_file_encoding="utf-8",
133
+ env_nested_delimiter="__",
134
+ extra="ignore",
135
+ )
136
+
137
+ @model_validator(mode="after")
138
+ def _sync_environment_to_module(self) -> "BaseSettings":
139
+ """把 ``environment`` 写入模块全局,让 ``is_dev()`` / ``is_prod()`` 跨模块可读。"""
140
+ set_current_environment(self.environment)
141
+ return self
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dwyeapi
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary: Lightweight FastAPI infrastructure — exceptions, database, config, security, cache, pagination, logger
5
5
  License: MIT
6
6
  Requires-Python: >=3.11
@@ -1,90 +0,0 @@
1
- """FastAPI 项目通用 Pydantic Settings 基类。
2
-
3
- 除了 database_url / redis_url / secret_key 等基础字段外,还提供运行环境识别 API:
4
-
5
- - ``environment`` 字段: ``"dev"`` | ``"prod"``,默认 ``"prod"``(误配置时偏保守)
6
- - ``get_environment()`` / ``is_dev()`` / ``is_prod()``:业务代码读取当前环境
7
-
8
- 业务项目实例化 ``Settings()`` 时会自动把 environment 值写入模块级全局变量,
9
- 之后任何地方 import 即可读,避免把 Settings 实例到处传递。
10
- """
11
-
12
- from typing import Literal
13
-
14
- from pydantic import Field, model_validator
15
- from pydantic_settings import BaseSettings as PydanticBaseSettings
16
- from pydantic_settings import SettingsConfigDict
17
-
18
- Environment = Literal["dev", "prod"]
19
-
20
- _current_environment: Environment = "prod"
21
-
22
-
23
- def get_environment() -> Environment:
24
- """返回当前运行环境。
25
-
26
- 未实例化 Settings 前默认返回 ``"prod"`` (保守),业务 ``Settings()`` 加载
27
- 后会同步为配置值。
28
- """
29
- return _current_environment
30
-
31
-
32
- def is_dev() -> bool:
33
- """当前是否为开发环境。"""
34
- return _current_environment == "dev"
35
-
36
-
37
- def is_prod() -> bool:
38
- """当前是否为生产环境。"""
39
- return _current_environment == "prod"
40
-
41
-
42
- def set_current_environment(env: Environment) -> None:
43
- """内部使用: 由 BaseSettings 校验钩子或测试显式切换时调用。"""
44
- global _current_environment
45
- _current_environment = env
46
-
47
-
48
- class BaseSettings(PydanticBaseSettings):
49
- """FastAPI 项目共用的配置基类。
50
-
51
- 业务项目通过继承并追加项目专属字段使用,内置的 database_url / redis_url /
52
- secret_key 等字段覆盖最常用的基础设施需求,不需要每个项目重复声明。
53
- 配置来源默认为 ``.env`` 文件,嵌套字段使用双下划线 ``__`` 分隔。
54
- """
55
-
56
- database_url: str
57
- redis_url: str
58
- secret_key: str
59
- jwt_algorithm: str = "HS256"
60
- access_token_expire_minutes: int = 30
61
- environment: Environment = "prod"
62
- allowed_origins: list[str] = Field(default_factory=list)
63
-
64
- # Task module settings (task_ prefix)
65
- task_max_jobs: int = 5
66
- task_job_timeout: int = 3600
67
- task_failure_ttl: int = 86400
68
-
69
- # Logger module settings (log_ prefix)
70
- log_level: str = "INFO"
71
- log_dir: str | None = None
72
- log_filename: str = "app"
73
- log_max_bytes: int = 100 * 1024 * 1024
74
- log_retention: str = "30 days"
75
- log_console: bool = True
76
- log_serialize: bool = False
77
- log_intercept_stdlib: bool = True
78
-
79
- model_config = SettingsConfigDict(
80
- env_file=".env",
81
- env_file_encoding="utf-8",
82
- env_nested_delimiter="__",
83
- extra="ignore",
84
- )
85
-
86
- @model_validator(mode="after")
87
- def _sync_environment_to_module(self) -> "BaseSettings":
88
- """把 ``environment`` 写入模块全局,让 ``is_dev()`` / ``is_prod()`` 跨模块可读。"""
89
- set_current_environment(self.environment)
90
- return self
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes