Sample
sqlalchemy 2.0.51: sql.elements.BinaryExpression
Verified sample for pypi sqlalchemy 2.0.51: sql.elements.BinaryExpression. The contract ran on python 3.12 · linux debian/x64 · docker and passed.
sha256:8fe1f5e5eea816685d88874fea42a289ec038e01bd2bcf9cba005b7a5a7f580a
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 pip
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-06 |
Case
HOW- Goal
- verify sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51
- Packages
- Symbols
-
- sqlalchemy.sql.elements.BinaryExpression
- Created
- 2026-09-06T23:57:29Z
Contract
- sqlalchemy.sql.elements.BinaryExpression represents binary operations between SQL column expressions with left operand, right operand, and operator
- sqlalchemy.sql.elements.BinaryExpression can be instantiated directly with left element, right element, and an operator callable
- sqlalchemy.sql.elements.BinaryExpression supports bitwise inversion to produce a negated binary expression with corresponding inverted operator
- sqlalchemy.sql.elements.BinaryExpression compiles to SQL expression strings with parameter bindings and integrates into SELECT query WHERE clauses
Files
- PROMPT.md
- csx.json
- requirements.txt
- sample.py
- spec.json
- test/contract.py
Source
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.sql.elements.BinaryExpression 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.sql.elements.BinaryExpression
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:2afd88ba43fdd366eba59ff07fa4060bb91e03388f8dd2f0c114bdace09959f0","contract":["sqlalchemy.sql.elements.BinaryExpression represents binary operations between SQL column expressions with left operand, right operand, and operator","sqlalchemy.sql.elements.BinaryExpression can be instantiated directly with left element, right element, and an operator callable","sqlalchemy.sql.elements.BinaryExpression supports bitwise inversion to produce a negated binary expression with corresponding inverted operator","sqlalchemy.sql.elements.BinaryExpression compiles to SQL expression strings with parameter bindings and integrates into SELECT query WHERE clauses"],"goal":"verify sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.sql.elements.BinaryExpression"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"subject":"pkg:pypi/sqlalchemy@2.0.51","symbols":["sqlalchemy.sql.elements.BinaryExpression"],"verifierAdapter":"python@1"}
sqlalchemy==2.0.51
"""Demonstration of SQL binary expressions using sqlalchemy.sql.elements.BinaryExpression."""
from typing import Any, Callable, Tuple
import operator
import sqlalchemy as sa
from sqlalchemy.sql.elements import BinaryExpression
from sqlalchemy.dialects import sqlite
def create_binary_comparison(
column_name: str,
value: Any,
) -> BinaryExpression:
"""Create a BinaryExpression using a column comparison operator."""
col = sa.column(column_name)
expr = col == value
if not isinstance(expr, BinaryExpression):
raise TypeError(f"Expected BinaryExpression, got {type(expr)}")
return expr
def instantiate_binary_expression(
column_name: str,
value: Any,
op: Callable[..., Any] = operator.gt,
) -> BinaryExpression:
"""Explicitly instantiate a BinaryExpression with left, right, and operator."""
col = sa.column(column_name)
val = sa.literal(value)
return BinaryExpression(col, val, op)
def negate_binary_expression(expr: BinaryExpression) -> BinaryExpression:
"""Invert a BinaryExpression using the bitwise NOT operator."""
negated = ~expr
if not isinstance(negated, BinaryExpression):
raise TypeError(f"Expected BinaryExpression after negation, got {type(negated)}")
return negated
def inspect_binary_expression(expr: BinaryExpression) -> Tuple[Any, Any, Callable[..., Any]]:
"""Inspect the operands and operator of a BinaryExpression."""
return expr.left, expr.right, expr.operator
def compile_binary_expression(expr: BinaryExpression, literal_binds: bool = True) -> str:
"""Compile a BinaryExpression to SQL string representation."""
return str(expr.compile(dialect=sqlite.dialect(), compile_kwargs={"literal_binds": literal_binds}))
def build_filtered_query(table_name: str, expr: BinaryExpression) -> str:
"""Build and compile a SELECT statement filtered by the BinaryExpression."""
table = sa.table(table_name, expr.left)
stmt = sa.select(table).where(expr)
return str(stmt.compile(dialect=sqlite.dialect(), compile_kwargs={"literal_binds": True}))
{
"schemaVersion": 1,
"goal": "verify sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51",
"kind": "HOW",
"packages": [
"pkg:pypi/sqlalchemy@2.0.51"
],
"symbols": [
"sqlalchemy.sql.elements.BinaryExpression"
]
}
"""Contract verification tests for sqlalchemy.sql.elements.BinaryExpression."""
import os
import sys
import operator
# Ensure sample root directory is in sys.path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlalchemy.sql.elements import BinaryExpression, BindParameter, ColumnClause
from sqlalchemy.dialects import sqlite
import sample
def test_binary_expression_representation() -> None:
"""Assertion 1: sqlalchemy.sql.elements.BinaryExpression represents binary operations between SQL column expressions with left operand, right operand, and operator."""
expr = sample.create_binary_comparison("status", "active")
assert isinstance(expr, BinaryExpression)
left, right, op = sample.inspect_binary_expression(expr)
assert isinstance(left, ColumnClause)
assert left.name == "status"
assert isinstance(right, BindParameter)
assert right.value == "active"
assert op is operator.eq
def test_direct_instantiation() -> None:
"""Assertion 2: sqlalchemy.sql.elements.BinaryExpression can be instantiated directly with left element, right element, and an operator callable."""
gt_expr = sample.instantiate_binary_expression("score", 90, operator.gt)
assert isinstance(gt_expr, BinaryExpression)
assert gt_expr.left.name == "score"
assert gt_expr.right.value == 90
assert gt_expr.operator is operator.gt
add_expr = sample.instantiate_binary_expression("score", 10, operator.add)
assert isinstance(add_expr, BinaryExpression)
assert add_expr.operator is operator.add
def test_negation_inversion() -> None:
"""Assertion 3: sqlalchemy.sql.elements.BinaryExpression supports bitwise inversion to produce a negated binary expression with corresponding inverted operator."""
expr = sample.create_binary_comparison("status", "active")
negated = sample.negate_binary_expression(expr)
assert isinstance(negated, BinaryExpression)
assert negated.operator is operator.ne
assert negated.left.name == "status"
assert negated.right.value == "active"
# Double negation restores equality semantics
double_negated = sample.negate_binary_expression(negated)
assert isinstance(double_negated, BinaryExpression)
assert double_negated.operator is operator.eq
def test_compilation_and_select_integration() -> None:
"""Assertion 4: sqlalchemy.sql.elements.BinaryExpression compiles to SQL expression strings with parameter bindings and integrates into SELECT query WHERE clauses."""
expr = sample.create_binary_comparison("status", "active")
# Compile with literal binds
compiled_literal = sample.compile_binary_expression(expr, literal_binds=True)
assert compiled_literal == "status = 'active'"
# Compile with parameter placeholder
compiled_param = str(expr.compile(dialect=sqlite.dialect()))
assert compiled_param == "status = ?"
# Query integration in SELECT statement
query_str = sample.build_filtered_query("users", expr)
assert "WHERE users.status = 'active'" in query_str
def main() -> None:
test_binary_expression_representation()
test_direct_instantiation()
test_negation_inversion()
test_compilation_and_select_integration()
print("All sqlalchemy.sql.elements.BinaryExpression contract assertions passed successfully.")
if __name__ == "__main__":
main()
Origin Seeder
anonymous