샘플
sqlalchemy 2.0.51: create_engine
검증된 샘플 — pypi sqlalchemy 2.0.51: create_engine. python 3.12 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: create_engine returns an Engine instance…
sha256:0c546b87451af14578ff9dbdb4a7fc48f5b569f35baa9bd785c395408d283ab4
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
python linux 24 · ubuntu · glibc 2.39 x64 python python pip
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962… |
2026-08-27 |
케이스
HOW- 목표
- verify sqlalchemy.create_engine in pkg:pypi/sqlalchemy@2.0.51
- 심벌
-
- sqlalchemy.create_engine
- 환경
- python
- 생성일
- 2026-08-27T19:30:04Z
컨트랙트
- create_engine returns an Engine instance configured with the specified URL dialect, driver, and execution options.
- create_engine connect() provides connection context management and executes SQL statements.
- create_engine begin() provides transactional context management with automatic commit on normal exit and rollback on exception.
- create_engine supports connection pool configuration and engine.dispose() to close pooled connections.
- create_engine raises ArgumentError when provided an invalid database URL string.
파일
- PROMPT.md
- csx.json
- requirements.txt
- sample.py
- spec.json
- test/contract.py
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify sqlalchemy.create_engine in pkg:pypi/sqlalchemy@2.0.51
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/sqlalchemy@2.0.51
Demonstrate these symbols/APIs:
- sqlalchemy.create_engine
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:4197ab723c6ce88339f2c1fe237bea2d7ff86dbd6cff1662d3fa5e867120d71d","contract":["create_engine returns an Engine instance configured with the specified URL dialect, driver, and execution options.","create_engine connect() provides connection context management and executes SQL statements.","create_engine begin() provides transactional context management with automatic commit on normal exit and rollback on exception.","create_engine supports connection pool configuration and engine.dispose() to close pooled connections.","create_engine raises ArgumentError when provided an invalid database URL string."],"goal":"verify sqlalchemy.create_engine in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.create_engine"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"subject":"pkg:pypi/sqlalchemy@2.0.51","symbols":["sqlalchemy.create_engine"],"verifierAdapter":"python@1"}
greenlet==3.5.5
sqlalchemy==2.0.51
typing-extensions==4.16.0
"""SQLAlchemy 2.0 create_engine usage and verification sample."""
from typing import List, Tuple
from sqlalchemy import create_engine, text
from sqlalchemy.engine import Engine
def initialize_engine(db_url: str = "sqlite:///:memory:", echo: bool = False) -> Engine:
"""Create and configure a SQLAlchemy Engine."""
return create_engine(db_url, echo=echo)
def setup_schema(engine: Engine) -> None:
"""Create sample tables using an engine transaction."""
with engine.begin() as conn:
conn.execute(
text(
"CREATE TABLE IF NOT EXISTS users ("
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
" username TEXT NOT NULL,"
" email TEXT NOT NULL"
")"
)
)
def insert_user(engine: Engine, username: str, email: str) -> int:
"""Insert a user and return the inserted row id."""
with engine.begin() as conn:
result = conn.execute(
text("INSERT INTO users (username, email) VALUES (:username, :email)"),
{"username": username, "email": email},
)
return result.lastrowid or 0
def fetch_all_users(engine: Engine) -> List[Tuple[int, str, str]]:
"""Query and return all user records."""
with engine.connect() as conn:
result = conn.execute(text("SELECT id, username, email FROM users ORDER BY id"))
return [(row.id, row.username, row.email) for row in result]
if __name__ == "__main__":
engine = initialize_engine("sqlite:///:memory:", echo=False)
setup_schema(engine)
user_id = insert_user(engine, "alice", "alice@example.com")
users = fetch_all_users(engine)
print(f"Inserted user id: {user_id}, total users: {len(users)}")
engine.dispose()
{
"schemaVersion": 1,
"goal": "verify sqlalchemy.create_engine in pkg:pypi/sqlalchemy@2.0.51",
"kind": "HOW",
"packages": [
"pkg:pypi/sqlalchemy@2.0.51"
],
"symbols": [
"sqlalchemy.create_engine"
]
}
"""Contract verification test for sqlalchemy.create_engine in SQLAlchemy 2.0."""
import os
import sys
# Ensure project root is on sys.path for local module imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlalchemy import create_engine, text
from sqlalchemy.engine import Engine, Connection
from sqlalchemy.exc import ArgumentError
from sample import (
initialize_engine,
setup_schema,
insert_user,
fetch_all_users,
)
def test_engine_creation_and_properties() -> None:
# 1. create_engine returns an Engine instance configured with the specified URL dialect, driver, and execution options.
engine = initialize_engine("sqlite:///:memory:", echo=False)
assert isinstance(engine, Engine), f"Expected Engine instance, got {type(engine)}"
assert engine.name == "sqlite"
assert engine.dialect.name == "sqlite"
assert str(engine.url) == "sqlite:///:memory:"
assert engine.echo is False
engine.dispose()
def test_engine_connect() -> None:
# 2. create_engine connect() provides connection context management and executes SQL statements.
engine = create_engine("sqlite:///:memory:")
with engine.connect() as conn:
assert isinstance(conn, Connection)
result = conn.execute(text("SELECT 1 + 1 AS sum_val"))
row = result.fetchone()
assert row is not None
assert row[0] == 2
assert row.sum_val == 2
engine.dispose()
def test_engine_begin_transactions() -> None:
# 3. create_engine begin() provides transactional context management with automatic commit on normal exit and rollback on exception.
engine = create_engine("sqlite:///:memory:")
setup_schema(engine)
# Insert user in a committed transaction
user_id = insert_user(engine, "alice", "alice@example.com")
assert user_id > 0
users = fetch_all_users(engine)
assert len(users) == 1
assert users[0][1] == "alice"
# Verify rollback on exception in begin() block
try:
with engine.begin() as conn:
conn.execute(
text("INSERT INTO users (username, email) VALUES (:username, :email)"),
{"username": "bob", "email": "bob@example.com"},
)
raise RuntimeError("Intentional failure to trigger rollback")
except RuntimeError:
pass
users_after_rollback = fetch_all_users(engine)
assert len(users_after_rollback) == 1
engine.dispose()
def test_engine_pool_and_dispose() -> None:
# 4. create_engine supports connection pool configuration and engine.dispose() to close pooled connections.
pooled_engine = create_engine("sqlite:///:memory:", pool_pre_ping=True)
with pooled_engine.connect() as conn:
result = conn.execute(text("SELECT 42"))
assert result.scalar() == 42
pooled_engine.dispose()
def test_engine_invalid_url() -> None:
# 5. create_engine raises ArgumentError when provided an invalid database URL string.
try:
create_engine("invalid_url_without_scheme")
raise AssertionError("Expected ArgumentError for invalid database URL")
except ArgumentError:
pass
def main() -> None:
test_engine_creation_and_properties()
test_engine_connect()
test_engine_begin_transactions()
test_engine_pool_and_dispose()
test_engine_invalid_url()
print("CONTRACT PASS: sqlalchemy.create_engine verified offline")
if __name__ == "__main__":
main()
오리진 시더
익명