aiteamutils 0.2.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.
@@ -0,0 +1,27 @@
1
+ # Dependencies
2
+ node_modules/
3
+ __pycache__/
4
+ *.pyc
5
+ .env
6
+
7
+ # Build
8
+ dist/
9
+ build/
10
+ .svelte-kit/
11
+
12
+ # IDE
13
+ .vscode/
14
+ .idea/
15
+
16
+ # Client specific
17
+ clients/
18
+ !clients/.gitkeep
19
+ !frontend/src/clients
20
+
21
+ # Logs
22
+ *.log
23
+ npm-debug.log*
24
+
25
+ # System
26
+ .DS_Store
27
+ Thumbs.db
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: aiteamutils
3
+ Version: 0.2.0
4
+ Summary: AI Team Utilities
5
+ Project-URL: Homepage, https://github.com/yourusername/aiteamutils
6
+ Project-URL: Issues, https://github.com/yourusername/aiteamutils/issues
7
+ Author: AI Team
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.8
12
+ Requires-Dist: fastapi
13
+ Requires-Dist: python-jose
14
+ Requires-Dist: sqlalchemy
15
+ Description-Content-Type: text/markdown
16
+
17
+ # AI Team Core Utils
18
+
19
+ AI Team Platform의 공통 유틸리티 패키지입니다.
20
+
21
+ ## 설치 방법
22
+
23
+ ```bash
24
+ pip install ai-team-core-utils
25
+ ```
26
+
27
+ ## 사용 예시
28
+
29
+ ```python
30
+ from ai_team_core_utils.database import DatabaseManager
31
+ from ai_team_core_utils.base_model import Base
32
+
33
+ # DB 매니저 초기화
34
+ db = DatabaseManager("postgresql+asyncpg://user:pass@localhost/db")
35
+
36
+ # DB 세션 사용
37
+ async with db.get_session() as session:
38
+ # DB 작업 수행
39
+ pass
40
+
41
+ # 예외 처리
42
+ from ai_team_core_utils.exceptions import CustomException, ErrorCode
43
+
44
+ try:
45
+ # 작업 수행
46
+ pass
47
+ except CustomException as e:
48
+ # 에러 처리
49
+ print(e.to_dict())
50
+ ```
51
+
52
+ ## 주요 기능
53
+
54
+ - 데이터베이스 유틸리티
55
+ - 세션 관리
56
+ - 트랜잭션 관리
57
+ - 기본 CRUD 작업
58
+
59
+ - 인증/인가 유틸리티
60
+ - JWT 토큰 관리
61
+ - 비밀번호 해싱
62
+ - Rate Limiting
63
+
64
+ - 예외 처리
65
+ - 표준화된 에러 코드
66
+ - 에러 체인 추적
67
+ - 로깅 통합
68
+
69
+ - 공통 모델
70
+ - 기본 모델 클래스
71
+ - 타입 검증
72
+ - 유효성 검사
@@ -0,0 +1,56 @@
1
+ # AI Team Core Utils
2
+
3
+ AI Team Platform의 공통 유틸리티 패키지입니다.
4
+
5
+ ## 설치 방법
6
+
7
+ ```bash
8
+ pip install ai-team-core-utils
9
+ ```
10
+
11
+ ## 사용 예시
12
+
13
+ ```python
14
+ from ai_team_core_utils.database import DatabaseManager
15
+ from ai_team_core_utils.base_model import Base
16
+
17
+ # DB 매니저 초기화
18
+ db = DatabaseManager("postgresql+asyncpg://user:pass@localhost/db")
19
+
20
+ # DB 세션 사용
21
+ async with db.get_session() as session:
22
+ # DB 작업 수행
23
+ pass
24
+
25
+ # 예외 처리
26
+ from ai_team_core_utils.exceptions import CustomException, ErrorCode
27
+
28
+ try:
29
+ # 작업 수행
30
+ pass
31
+ except CustomException as e:
32
+ # 에러 처리
33
+ print(e.to_dict())
34
+ ```
35
+
36
+ ## 주요 기능
37
+
38
+ - 데이터베이스 유틸리티
39
+ - 세션 관리
40
+ - 트랜잭션 관리
41
+ - 기본 CRUD 작업
42
+
43
+ - 인증/인가 유틸리티
44
+ - JWT 토큰 관리
45
+ - 비밀번호 해싱
46
+ - Rate Limiting
47
+
48
+ - 예외 처리
49
+ - 표준화된 에러 코드
50
+ - 에러 체인 추적
51
+ - 로깅 통합
52
+
53
+ - 공통 모델
54
+ - 기본 모델 클래스
55
+ - 타입 검증
56
+ - 유효성 검사
@@ -0,0 +1,60 @@
1
+ from .base_model import Base
2
+ from .database import DatabaseManager
3
+ from .exceptions import (
4
+ CustomException,
5
+ ErrorCode,
6
+ custom_exception_handler,
7
+ request_validation_exception_handler,
8
+ sqlalchemy_exception_handler,
9
+ generic_exception_handler
10
+ )
11
+ from .security import (
12
+ verify_password,
13
+ hash_password,
14
+ create_jwt_token,
15
+ verify_jwt_token,
16
+ rate_limit,
17
+ RateLimitExceeded
18
+ )
19
+ from .base_service import BaseService
20
+ from .base_repository import BaseRepository
21
+ from .validators import validate_with
22
+ from .enums import ActivityType
23
+ from .cache import CacheManager
24
+
25
+ __version__ = "0.1.0"
26
+
27
+ __all__ = [
28
+ # Base Models
29
+ "Base",
30
+ "BaseService",
31
+ "BaseRepository",
32
+
33
+ # Database
34
+ "DatabaseManager",
35
+
36
+ # Exceptions
37
+ "CustomException",
38
+ "ErrorCode",
39
+ "custom_exception_handler",
40
+ "request_validation_exception_handler",
41
+ "sqlalchemy_exception_handler",
42
+ "generic_exception_handler",
43
+
44
+ # Security
45
+ "verify_password",
46
+ "hash_password",
47
+ "create_jwt_token",
48
+ "verify_jwt_token",
49
+ "rate_limit",
50
+ "RateLimitExceeded",
51
+
52
+ # Validators
53
+ "validate_with",
54
+
55
+ # Enums
56
+ "ActivityType",
57
+
58
+ # Cache
59
+ "CacheManager"
60
+ ]
@@ -0,0 +1,81 @@
1
+ from datetime import datetime, timezone
2
+ from typing import Any, Dict, TypeVar, Generic, Optional
3
+ from ulid import ULID
4
+ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
5
+ from sqlalchemy import Column, String, PrimaryKeyConstraint, UniqueConstraint
6
+ from sqlalchemy.dialects.postgresql import TIMESTAMP
7
+ from pydantic import BaseModel, ConfigDict
8
+ from pydantic import Field
9
+
10
+ class Base(DeclarativeBase):
11
+ """SQLAlchemy 기본 모델"""
12
+ pass
13
+
14
+ class BaseColumn(Base):
15
+ """공통 설정 및 메서드를 제공하는 BaseColumn"""
16
+ __abstract__ = True
17
+
18
+ ulid: Mapped[str] = mapped_column(
19
+ String,
20
+ primary_key=True,
21
+ unique=True,
22
+ default=lambda: str(ULID()),
23
+ doc="ULID",
24
+ nullable=False
25
+ )
26
+ created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
27
+ updated_at: Mapped[datetime] = mapped_column(
28
+ default=datetime.utcnow,
29
+ onupdate=datetime.utcnow
30
+ )
31
+ is_deleted: Mapped[bool] = mapped_column(
32
+ default=False,
33
+ index=True
34
+ )
35
+
36
+ def to_dict(self) -> Dict[str, Any]:
37
+ """모델을 딕셔너리로 변환합니다.
38
+
39
+ Returns:
40
+ Dict[str, Any]: 모델의 속성을 포함하는 딕셔너리
41
+ """
42
+ result = {}
43
+
44
+ # 테이블 컬럼 처리
45
+ for column in self.__table__.columns:
46
+ value = getattr(self, column.name)
47
+ if isinstance(value, datetime):
48
+ value = value.isoformat()
49
+ result[column.name] = value
50
+
51
+ # Relationship 처리 (이미 로드된 관계만 처리)
52
+ for relationship in self.__mapper__.relationships:
53
+ if relationship.key == "organizations": # 순환 참조 방지
54
+ continue
55
+ try:
56
+ value = getattr(self, relationship.key)
57
+ if value is not None:
58
+ if isinstance(value, list):
59
+ result[relationship.key] = [item.to_dict() for item in value]
60
+ else:
61
+ result[relationship.key] = value.to_dict()
62
+ else:
63
+ result[relationship.key] = None
64
+ except Exception:
65
+ result[relationship.key] = None
66
+
67
+ return result
68
+
69
+ class BaseSchema(BaseModel):
70
+ """공통 설정 및 메서드를 제공하는 BaseSchema"""
71
+ model_config = ConfigDict(
72
+ str_strip_whitespace=True,
73
+ extra="allow",
74
+ from_attributes=True,
75
+ populate_by_name=True,
76
+ use_enum_values=True
77
+ )
78
+
79
+ def to_dict(self) -> Dict[str, Any]:
80
+ """모델을 딕셔너리로 변환"""
81
+ return self.model_dump()