Conversation
…ity) TinybirdApi.analyze() wraps POST /v0/analyze, inferring column names, ClickHouse types, and CSV dialect from a local file or URL, matching `tb datasource analyze <url_or_file>`. tinybird_sdk.infer.parse_analyze_response() turns the response into a structured AnalyzedSchema, and generate_schema_code() emits ready-to-use define_datasource(...) source with t.* validators, reusing the same type-mapping codegen already used for reverse codegen (live workspace -> Python). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TinybirdApi.analyze()wraps the Tinybird Analyze API (POST /v0/analyze), inferring column names, ClickHouse types, and (for CSV) dialect from a local file or URL — matchingtb datasource analyze <url_or_file>. Follows the sameurl/file(form-encoded vs. multipart) convention as the existingappend_datasource().tinybird_sdk.infer.parse_analyze_response()parses the raw API response into a structuredAnalyzedSchema, tolerating two known response shapes: ananalysis.columnslist of{name, recommended_type}entries, or ananalysis.schema/schemaClickHouse DDL-like string as a fallback.tinybird_sdk.infer.generate_schema_code()turns anAnalyzedSchemainto ready-to-pastedefine_datasource(...)source witht.*validators, reusing the existingcodegen.clickhouse_type_to_validatortype-mapping (the same one used for reverse codegen of live workspace resources), so inferred and reverse-codegen'd datasources read identically.Closes https://linear.app/tinybird/issue/PROTM-2263/python-sdk-add-schema-inference-from-real-sample-data
Design notes
tinybird analyzeCLI subcommand — it ships the library-level helper (API method + parsing + codegen) the ticket asks for. A thin CLI wrapper mirroringtb datasource analyzewould be a natural, separable follow-up once this API shape is validated against the real Analyze API contract in a live environment./v0/analyzecould not be verified against live docs/API from this sandbox, soparse_analyze_response()is intentionally tolerant of both acolumnslist and a DDL-styleschemastring, and raises a clearValueErrorif neither is present rather than silently guessing. Worth a quick confirmation against a real analyze response before relying on this in production.Checklist
lint,typecheck,test)pre-commit run --all-filespasses locally (secrets/gitleaks fails in this sandbox on an unrelated SSL cert error fetching its pre-commit env, not something introduced by this change)README.md) — new "Schema Inference Helpers" exampleCHANGELOG.mdwas updated when user-facing behavior changed