Repository navigation
SDK Python: client generato, autenticazione OAuth2, CLI e CI - #1
Merged
Merged
Conversation
Copied from the Shellrent application: nullable references as anyOf with null, nullable data and meta in ApiError and in the inline envelopes, required fields on the response schemas, 429 documented on the throttled operations and on the token endpoint (OAuth2 format), OrderPayRequest and SmsCreateRequest as plain objects, payOrders data as Payment or null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bin/generate runs the generator and Ruff, both pinned, through uvx, with --fail-on-warning so that no operation is skipped silently, and replaces src/shellrent_sdk/client entirely. The content type overrides return the PDF, XML and p7m downloads as File with the raw bytes: without them the PDFs are dropped and the XML is decoded as text. The generated code is never edited by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- shellrent_sdk.auth: ClientCredentials, TokenStore with MemoryTokenStore and FileTokenStore (0700 directory, 0600 files, atomic writes), and OAuth2Auth, an httpx.Auth that requests the token from the auth flow, reuses it until 60 s before it expires, retries once after a 401 and is safe across threads and event loops. The secret is never cached. - shellrent_sdk.http: RetryTransport (429 with Retry-After, sync and async, following the proxy and certificate environment like httpx) and client_args() for the httpx clients. - create_client(), returning the generated AuthenticatedClient, and unwrap()/ApiException for the documented error responses. - The shellrent command (shellrent api, shellrent token), modelled on gh api, with the token cached in a file. - auth, http and the CLI do not depend on the generated code: they are used by shellrent-internal-sdk too. - Packaging with hatchling and hatch-vcs, uv.lock, Ruff and strict mypy, pytest with httpx.MockTransport, CI on Python 3.11-3.14 plus the lowest dependencies and the regeneration check, release to PyPI with Trusted Publishing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Prima versione dell'SDK Python ufficiale delle API pubbliche Shellrent (
shellrent-sdksu PyPI, packageshellrent_sdk), con la stessa impostazione dell'SDK PHP: client generato dalla spec, a mano solo autenticazione, creazione del client, CLI, test, documentazione e CI.Commit
spec/openapi.yamlaggiornata alla versione 3.1 prodotta dall'applicazione.src/shellrent_sdk/client/generato dabin/generatecon openapi-python-client 0.29.1 e Ruff, entrambi con versione fissata ed eseguiti conuvx. Non va revisionato riga per riga: la CI lo rigenera e fallisce se differisce.shellrent_sdk.auth:ClientCredentials,TokenStore(MemoryTokenStore,FileTokenStore) eOAuth2Auth, unhttpx.Authche chiede il token dal flusso di autenticazione, lo riusa fino a 60 s prima della scadenza, ripete una volta dopo un 401 ed è thread-safe.shellrent_sdk.http:RetryTransport, che ripete i 429 rispettandoRetry-After(sync e async), eclient_args().create_client(),unwrap()eApiException.shellrent(shellrent api,shellrent token).Scelte da valutare
create_client()restituisceAuthenticatedCliente nonClient: le funzioni delle operazioni protette lo richiedono nel tipo. Il token lo metteOAuth2Autha ogni richiesta, non il campotokendel client.unwrap(op.sync_detailed(...))restituisce il body tipizzato oppure sollevaApiException(status_code,error,headers,content), compreso il 429 che resta dopo i retry.RetryTransportè un'unica classe sync e async, perché il client generato passa gli stessihttpx_argssia ahttpx.Clientsia ahttpx.AsyncClient. Segue le variabili d'ambienteHTTP(S)_PROXY,ALL_PROXY,NO_PROXY,SSL_CERT_FILEeSSL_CERT_DIRcome httpx. I proxy li legge conurllib.request, perché httpx non ha un'API pubblica per farlo.FileTokenStorecrea la cartella con permessi 0700 e i file con 0600. La CLI mette in cache il token su file per default;SHELLRENT_TOKEN_CACHEindica un'altra cartella oppureoff.auth,httpe la CLI non importano il codice generato: li userà ancheshellrent-internal-sdk, etest_layers.pylo verifica.Verifica
tests/fixtures/tls/server-key.pemè una chiave di prova, valida solo per127.0.0.1/localhost; la chiave della CA non è stata conservata.SHELLRENT_CLIENT_IDeSHELLRENT_CLIENT_SECRET(più, se serve, la variabileSHELLRENT_API_URL);test_errors.pyrichiede lo scopepurchases:read.Prima del primo rilascio
shellrent-sdk(repositoryshellrent/shellrent-sdk-python, workflowrelease.yml, environmentpypi).pypicon i revisori obbligatori e aggiungere i secret per i test di integrazione.vX.Y.Z:release.ymlbuilda, controlla che la versione coincida con il tag e pubblica dopo l'approvazione.Aperto sulla spec
getHealthnon sia soggetto a throttling: è l'unica operazione protetta senza 429 documentato.payOrdersegetHostingAntivirussono schemi inline, quindi le classi si chiamanoPayOrdersResponse200eGetHostingAntivirusResponse200.🤖 Generated with Claude Code