Skip to main content

Async Alchemy

SQLAlchemy를 사용한 비동기 데이터베이스 연결 관리자입니다. 이 라이브러리는 Python의 비동기 프로그래밍을 활용하여 효율적인 데이터베이스 연결 관리를 제공합니다.

주요 기능

  • 비동기 데이터베이스 연결 관리
  • 커넥션 풀링을 통한 효율적인 리소스 관리
  • 세션 관리 기능 제공
  • 환경 설정 기반의 유연한 데이터베이스 설정

설치 방법

pip를 사용한 설치

# 가상환경 생성 및 활성화
python -m venv .venv
source .venv/bin/activate  # macOS/Linux
# Windows: .venv\Scripts\activate

# 패키지 설치
pip install sqlalchemy asyncpg greenlet pydantic python-dotenv

uv를 사용한 설치

# uv 설치 (처음 한 번만)
curl -LsSf https://astral.sh/uv/install.sh | sh

# 가상환경 생성 및 의존성 설치
uv venv
source .venv/bin/activate  # macOS/Linux
# Windows: .venv\Scripts\activate

uv pip install sqlalchemy asyncpg greenlet pydantic python-dotenv

사용 방법

  1. 데이터베이스 설정:
from app.modules.configs import DatabaseConfig, AsyncPostgresDsn

# DSN 설정
dsn = AsyncPostgresDsn(
    host="localhost",
    port=5432,
    user="user",
    password="password",
    db="database"
)

# 데이터베이스 설정
config = DatabaseConfig(
    dsn=dsn,
    echo=False,  # SQL 로깅
    pool_size=5,  # 커넥션 풀 크기
    max_overflow=10  # 최대 추가 연결 수
)
  1. 데이터베이스 연결 관리자 생성:
from app.main import Database
from sqlalchemy.orm import DeclarativeBase

# 모델 베이스 클래스 정의
class Base(DeclarativeBase):
    pass

# 데이터베이스 관리자 생성
db = Database(config=config, base=Base)

# 데이터베이스 초기화 (테이블 생성)
await db.initialize()
  1. 세션 사용:
# 세션 컨텍스트 매니저 사용
async with db.session.begin() as session:
    # 데이터베이스 작업 수행
    result = await session.execute(query)
    await session.commit()

# 작업 완료 후 리소스 정리
await db.dispose()

테스트

테스트를 실행하기 위해 추가 의존성을 설치합니다:

# pip 사용
pip install pytest pytest-asyncio

# 또는 uv 사용
uv pip install pytest pytest-asyncio

테스트 실행:

pytest tests/ -v

환경 변수 설정

.env 파일을 생성하여 데이터베이스 연결 정보를 관리할 수 있습니다:

POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=database
POSTGRES_USER=user
POSTGRES_PASSWORD=password

라이선스

MIT License

Test Coverage

--------- coverage: platform darwin, python 3.11.11-final-0 ----------
Name                     Stmts   Miss  Cover
--------------------------------------------
app/__init__.py              2      0   100%
app/main.py                 30      0   100%
app/modules/configs.py      43      6    86%
app/modules/session.py      25     14    44%
--------------------------------------------
TOTAL                      100     20    80%

Metadata

Release files for async-db-alchemy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-db-alchemy 0.1.0
File Size Uploaded Provenance
async_db_alchemy-0.1.0.tar.gz 34.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for async-db-alchemy 0.1.0
File Interpreter ABI Platform
async_db_alchemy-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.5 kB

Release files / async_db_alchemy-0.1.0.tar.gz

Download URL async_db_alchemy-0.1.0.tar.gz
Size 34.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8185e38f982b53e1a010ef7fca54f851ea520679f0792540e8e543e93c37fdd4
BLAKE2b-256 checksum
How to use checksums
68fdfd6e259955d10d9232d1e08a6ad6cad44fb19390ffb47c64eebf44abde98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.24

Release files / async_db_alchemy-0.1.0-py3-none-any.whl

Download URL async_db_alchemy-0.1.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
923f700216bef9e73bca01411e8034c9e49cbc266b0634df34c1fb437604dc1f
BLAKE2b-256 checksum
How to use checksums
d76e8f02577adec5f47270c3cca1a12c1cc39777fec32921472c1eef5fb4de1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.24

Security for async-db-alchemy 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page