Releases: phalt/clientele
Releases · phalt/clientele
1.11.0
GraphQLClient support
- A method for building GraphQL integrations has been introduced.
- It follows the "Clientele" pattern of the standard
APIClient.
Query example:
@client.query('''
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
name
stargazerCount
}
}
''')
def get_repo(owner: str, name: str, result: RepositoryData) -> Repository:
return result.repositoryMutation example:
@client.mutation('''
mutation($title: String!) {
createIssue(input: {title: $title}) {
issue { id title }
}
}
''')
def create_issue(title: str, result: IssueData) -> Issue:
return result.createIssue.issue1.10.0
1.9.2
This release includes testing tools to make API integration testing easier.
ResponseFactory
- Added
ResponseFactorytoclientele.testingfor quick response fixtures. - Create common HTTP responses easily:
ok(),created(),not_found(),bad_request(),internal_server_error(), and more.
NetworkErrorFactory
- Added
NetworkErrorFactoryfactory toclientele.testingfor simulating network-level failures. - Simulate common network errors like
timeout(),connection_refused(),connection_reset(), anddns_failure(). FakeHTTPBackendnow supportsqueue_error()to queue errors for specific paths.
1.9.1
1.9.0
Retry support
- Built-in
retries.retrydecorator for handling retry logic. - This is built on top of
stamina- a popular and reliable retry package. - The retry logic is customised to suit Clientele's exception handling.
from clientele import api, retries
client = api.APIClient(api.BaseConfig(base_url="https://httpbin.org/"))
@retries.retry(attempts=3)
@client.get("/status/{status_code}")
def get_status(status_code: int, result: dict) -> dict:
return resultImproved testing
- We have drastically improved the testing support for Clientele.
- The
FakeHTTPBackendis now designed for testing. - The
queue_responsemethod now takes ahttp.Responseobject as well as the path. - The new
configure_client_for_testingfunction accepts an existing client and then returns it with a new testing backend.
from clientele.testing import configure_client_for_testing
from clientele import http
from my_api_client import client, my_function
def my_test():
# Swap normal backend for a Fake HTTP backend
fake_backend: http.FakeHTTPBackend = configure_client_for_testing(my_api_client.client)
# Configure HTTP responses
fake_backend.queue_response(
path="/users",
response_obj=Response(
status_code=201,
content=b'{"id": 10, "name": "Bob"}',
headers={"content-type": "application/json"},
),
)
# Call function as normal, but it now calls the fake backend
response = my_function()Dropped explore command
- While it is a cool feature, it distracts from the purpose of Clientele, so it is being removed.
1.8.1
- Add
configuremethod toAPIClient- enabling reconfiguration of clients. Thank you Christian Assing for the contribution.
1.8.0
Request Logging
- Added optional request/response logging to
APIClientvia theloggerparameter inBaseConfig. Logs include method, URL, status code, and elapsed time in seconds. - Uses a
LoggerProtocol with@runtime_checkablefor flexibility.
CLI commands update
- A new command
start-apihas been introduced. - The new command will replace
scaffold-apiandgenerate-basicin 2.0.0 - Currently it behaves as an alias for both.
- If not url or file is provided, will call
generate-basic, otherwise it callsscaffold-api.
Start a basic client with one command:
uvx clientele start-api -o /path/to/my_client- Dropped the
generateandgenerate-classcommands from the CLI.
1.7.1
- Support for OpenAPI discriminated unions (
oneOf+discriminator). Schemas with discriminators now generate proper Pydantic discriminated unions usingtyping.Annotated[..., pydantic.Field(discriminator="...")]. scaffold-apinow adds mypy configuration to thepyproject.tomlthat is produced with a scaffolded client.
1.7.0
HTTP Backends
- Clientele now supports configurable HTTP backends.
- If you want to use
aiohttp,reqwestsorniquestsyou can write anHTTPBackendso Clientele can support it. - Clientele ships with a default
HttpxHTTPBackendthat will be used if no other is configured. - Introduces a new
clientele.http.Responsewrapper for generic handling of responses. - The
response_parsercallbacks now take the genericclientele.http.Responseinstead ofhttpx.Response. - Introduces a new
FakeHTTPBackendthat can be used for testing.
Direct requests
- An optional approach for making requests with Clientele is now available.
- This approach does not enforce the decorator pattern.
- But still offers smart data hydration and response mapping.
- Support for both async and sync.