CodeSampleX

示例

pydantic-settings 2.14.2: pydantic_settings.SettingsConfigDict

已验证示例 — pypi pydantic-settings 2.14.2: pydantic_settings.SettingsConfigDict. contract 在 python 3.12 · linux alpine/x64 · docker 上运行并通过.

sha256:1807e23acdeed8b24c53e41a6eab635528d4b6ce7831a5ef502a991da54c10fd

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 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 pydantic_settings.SettingsConfigDict in pkg:pypi/pydantic-settings@2.14.2
包
符号
  • pydantic_settings.SettingsConfigDict
创建时间
2026-08-27T19:32:23Z

契约

  1. SettingsConfigDict(env_prefix='APP_') prefixes environment variable lookup for settings fields
  2. SettingsConfigDict(env_nested_delimiter='__') parses nested model fields from delimited environment variables
  3. SettingsConfigDict(case_sensitive=True) requires exact case match for prefixed environment variables

文件

  • PROMPT.md
  • csx.json
  • requirements.txt
  • spec.json
  • test/contract.py

下载源代码构件 (tar.gz)

源代码

PROMPT.md
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 pydantic_settings.SettingsConfigDict in pkg:pypi/pydantic-settings@2.14.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/pydantic-settings@2.14.2
Demonstrate these symbols/APIs:
  - pydantic_settings.SettingsConfigDict

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.
csx.json
{"case":{"caseId":"case:sha256:65ec818bbc2996c88557f293dbbd9a9f06fba70b23004d0d3ed172c054656f9d","contract":["SettingsConfigDict(env_prefix='APP_') prefixes environment variable lookup for settings fields","SettingsConfigDict(env_nested_delimiter='__') parses nested model fields from delimited environment variables","SettingsConfigDict(case_sensitive=True) requires exact case match for prefixed environment variables"],"goal":"verify pydantic_settings.SettingsConfigDict in pkg:pypi/pydantic-settings@2.14.2","kind":"HOW","packages":["pkg:pypi/pydantic-settings@2.14.2"],"schemaVersion":1,"symbols":["pydantic_settings.SettingsConfigDict"]},"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/pydantic-settings@2.14.2"],"schemaVersion":1,"subject":"pkg:pypi/pydantic-settings@2.14.2","symbols":["pydantic_settings.SettingsConfigDict"],"verifierAdapter":"python@1"}
requirements.txt
pydantic-settings==2.14.2
pydantic==2.13.4
pydantic-core==2.46.4
annotated-types==0.8.0
typing-extensions==4.15.0
typing-inspection==0.4.2
python-dotenv==1.2.2
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pydantic_settings.SettingsConfigDict in pkg:pypi/pydantic-settings@2.14.2",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/pydantic-settings@2.14.2"
  ],
  "symbols": [
    "pydantic_settings.SettingsConfigDict"
  ]
}
test/contract.py
import os
from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict


class DatabaseConfig(BaseModel):
    host: str = "localhost"


class AppSettings(BaseSettings):
    model_config = SettingsConfigDict(
        env_prefix="APP_",
        env_nested_delimiter="__",
        case_sensitive=False,
    )
    host: str = "localhost"
    port: int = 8080
    database: DatabaseConfig = DatabaseConfig()


class StrictCaseSettings(BaseSettings):
    model_config = SettingsConfigDict(
        env_prefix="APP_",
        case_sensitive=True,
    )
    endpoint: str = "default_endpoint"


def main() -> None:
    tracked_keys = [
        "APP_HOST",
        "APP_PORT",
        "APP_DATABASE__HOST",
        "APP_ENDPOINT",
        "APP_endpoint",
        "HOST",
    ]
    saved_env = {k: os.environ.get(k) for k in tracked_keys}

    try:
        # Set environment variables
        os.environ["APP_HOST"] = "10.0.0.1"
        os.environ["APP_PORT"] = "9000"
        os.environ["APP_DATABASE__HOST"] = "db.internal"
        os.environ["HOST"] = "ignored.example.com"

        # 1. Test env_prefix and env_nested_delimiter
        settings = AppSettings()
        assert settings.host == "10.0.0.1", f"Expected '10.0.0.1', got '{settings.host}'"
        assert settings.port == 9000, f"Expected 9000, got {settings.port}"
        assert settings.database.host == "db.internal", f"Expected 'db.internal', got '{settings.database.host}'"

        # 2. Test case_sensitive=True
        os.environ["APP_ENDPOINT"] = "uppercase_val"
        strict_case = StrictCaseSettings()
        assert strict_case.endpoint == "default_endpoint", (
            f"Expected default 'default_endpoint' under case_sensitive=True, got '{strict_case.endpoint}'"
        )

        os.environ["APP_endpoint"] = "exact_val"
        strict_case_exact = StrictCaseSettings()
        assert strict_case_exact.endpoint == "exact_val", (
            f"Expected 'exact_val', got '{strict_case_exact.endpoint}'"
        )

    finally:
        for k, v in saved_env.items():
            if v is None:
                os.environ.pop(k, None)
            else:
                os.environ[k] = v


if __name__ == "__main__":
    main()

原始种子者

匿名