Python SDK for the OBP Accounting Service.
Project description
obp-accounting-sdk
Description
Python SDK for the OBP Accounting Service.
Usage
The API provides the following main classes to be used asynchronously:
obp_accounting_sdk.AsyncAccountingSessionFactory
obp_accounting_sdk.AsyncOneshotSession
and the corresponding synchronous versions:
obp_accounting_sdk.AccountingSessionFactory
obp_accounting_sdk.OneshotSession
The factory class must be instantiated only once, and a new session can be obtained by calling the oneshot_session
method used as a context manager:
subtype: ServiceSubtype = ...
proj_id: UUID = ...
estimated_count: int = ...
async with accounting_session_factory.oneshot_session(
subtype=subtype,
proj_id=proj_id,
count=estimated_count,
) as acc_session:
# actual logic
acc_session.count = actual_count
In the example above:
- The reservation with the accounting service happens when entering the context manager.
- The usage is sent to the accounting service when exiting the context manager, unless an exception is raised, because in this case we suppose that the actual business logic to be charged didn't get executed.
- The value of
estimated_count
is used for reservation, and it's used also for usage unless a new value is assigned toacc_session.count
.
Example
See the Demo app for a working example integrated in a simple FastAPI app.
If you installed tox
, you can set the required env variables and run the demo with:
export ACCOUNTING_BASE_URL=http://127.0.0.1:8100
export UVICORN_PORT=8000
tox -e demo
and call the endpoint after setting a valid project-id with:
export PROJECT_ID=8eb248a8-672c-4158-9365-b95286cba796
curl -vs "http://127.0.0.1:$UVICORN_PORT/query" \
-H "content-type: application/json" \
-H "project-id: $PROJECT_ID" \
--data-binary @- <<EOF
{"input_text": "my query"}
EOF
Contribution Guidelines
See CONTRIBUTING.
Acknowledgment
The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.
For license and authors, see LICENSE and AUTHORS respectively.
Copyright © 2024 Blue Brain Project/EPFL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file obp_accounting_sdk-0.1.1.tar.gz
.
File metadata
- Download URL: obp_accounting_sdk-0.1.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca61805d7ec08c5e666c6b818d2fd35d2b7e61e9d79c6745caee00f09ef5f272 |
|
MD5 | 7f6622ff3dd3db710bc548c30f05eb70 |
|
BLAKE2b-256 | 8a332852b53834df90fdecf5ab4dd8ac102bf8b48602d64a7029dec150a0429c |
File details
Details for the file obp_accounting_sdk-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: obp_accounting_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f12daab355e12eae0740bef93080af63129cf9e2337901d0cb8ae4beca46009c |
|
MD5 | 72ba85d18c60cbb51ccb7033cd6e60da |
|
BLAKE2b-256 | bf373c85e055e33b6d1792fbed86ee25fb4844d192f72c4daecd4816a36b91eb |