Coverage for src/fluree_py/http/mixin/commit.py: 100%
19 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 03:03 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 03:03 +0000
1"""Mixins for committing transactions to the Fluree ledger."""
3from typing import Generic, TypeVar
5from httpx import AsyncClient, Client
7from fluree_py.http.protocol.mixin.commit import SupportsAsyncCommit, SupportsCommit
8from fluree_py.http.protocol.mixin.request import SupportsRequestCreation
9from fluree_py.http.response import FlureeResponse
11T = TypeVar("T", bound=SupportsRequestCreation)
14class CommitMixin(SupportsCommit, Generic[T]):
15 """Synchronous commit functionality for Fluree transactions."""
17 def commit(self: T) -> FlureeResponse:
18 """Executes the transaction synchronously.
20 Exceptions:
21 httpx.RequestError: If the HTTP request fails.
22 TypeError: If the type parameter cannot be resolved.
23 """
24 request = self.get_request()
25 with Client() as client:
26 response = client.send(request)
27 return FlureeResponse(response=response)
30class AsyncCommitMixin(SupportsAsyncCommit, Generic[T]):
31 """Asynchronous commit functionality for Fluree transactions."""
33 async def acommit(self: T) -> FlureeResponse:
34 """Executes the transaction asynchronously.
36 Exceptions:
37 httpx.RequestError: If the HTTP request fails.
38 TypeError: If the type parameter cannot be resolved.
39 """
40 request = self.get_request()
41 async with AsyncClient() as client:
42 response = await client.send(request)
43 return FlureeResponse(response=response)
46class CommitableMixin(CommitMixin[T], AsyncCommitMixin[T], Generic[T]):
47 """Combines synchronous and asynchronous commit capabilities."""