v2.5.0: CLI-credentials auth + scraper-core dedup - #46
Open
karaposu wants to merge 3 commits into
Open
Conversation
The 7 search classes hand-copied the base's __init__ and context manager; they now inherit a shared core. Amazon/ChatGPT/LinkedIn search gain the standard env-token fallback. No public API or behavior removed.
…gent Token resolution: param → env (BRIGHTDATA_API_TOKEN, BRIGHTDATA_API_KEY) → ~/.../brightdata-cli/credentials.json (read-only) → actionable error. User-agent is now brightdata-sdk-python/<ver> (auth=param|env|cli_credentials).
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.
Python half of the cross-SDK task "SDKs resolve credentials from the CLI store + report auth source in user-agent" (the JS half lives in
sdk-js).What this does
Before: the SDK only accepted a token via the
token=parameter or theBRIGHTDATA_API_TOKENenv var — a user who had already runbrightdata loginstill had to copy an API key by hand.Now: with no token given, the SDK falls back to the key the CLI already saved. One login authenticates everything:
Resolution order (first hit wins):
token=parameter →auth=paramBRIGHTDATA_API_TOKEN, thenBRIGHTDATA_API_KEYenv vars →auth=env…/brightdata-cli/credentials.json(read-only) →auth=cli_credentialsbrightdata login, the env var, and the token page)Every request now reports how the token was obtained — making SDK onboarding measurable (feeds the
sdk_auth_sourceMixpanel property):Ticket checklist
src/brightdata/cli_credentials.py— per-platform path (Linux / macOS / Windows%APPDATA%) +read_cli_credentials()that never raises and never writesBrightDataClientandSyncBrightDataClient(sync delegates to async — pinned by test)brightdata-cli/, never readsconfig.json(pinned by test)Note: engines created by standalone scraper construction (e.g.
AmazonScraper(bearer_token=...)without a client) keep today's behavior and omit the(auth=…)field — the ticket scopes the fallback to the client constructors; extending it there is a small follow-up.Also included
Internal: shared
ScraperCore. The 7 search classes each hand-copied the base scraper's__init__+ context manager and had drifted (Amazon/ChatGPT/LinkedIn search lacked the env-token fallback). They now inherit one shared core: −174 lines, drift gone — and the standalone follow-up above becomes a one-place edit instead of 8.Tests: 321 passing (57 new). Version → 2.5.0.