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.AsyncAccountingSessionFactoryobp_accounting_sdk.AsyncOneshotSession
and the corresponding synchronous versions:
obp_accounting_sdk.AccountingSessionFactoryobp_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 = ...
user_id: UUID = ...
name: str | None = ...
estimated_count: int = ...
async with accounting_session_factory.oneshot_session(
subtype=subtype,
proj_id=proj_id,
user_id=user_id,
name=name,
count=estimated_count,
) as acc_session:
# actual logic
acc_session.count = actual_count
acc_session.name = actual_name
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_countis used for reservation, and it's used also for usage unless a new value is assigned toacc_session.count.
Accounting session can be also used without the context manager:
subtype: ServiceSubtype = ...
proj_id: UUID = ...
user_id: UUID = ...
name: str | None = ...
estimated_instances: int = ...
instance_type: str = ...
instances: int = ...
duration: int = ...
acc_session = accounting_session_factory.longrun_session(
subtype=subtype,
proj_id=proj_id,
user_id=user_id,
name=name,
instance_type="FARGATE",
instances=1,
duration=5,
)
await acc_session.make_reservation()
await acc_session.start() # start method is required only for longrun sessions.
# Actual logic
await acc_session.finish()
[!TIP] The integration with the Accounting service can be disabled by setting the env variable
ACCOUNTING_DISABLED=1before initializing theAsyncAccountingSessionFactoryorAccountingSessionFactoryobject.
Example
See the Demo app for a working example integrated in a simple FastAPI app.
If you installed tox, and if you have a running instance of the Accounting service, 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 and user-id with:
export PROJECT_ID=8eb248a8-672c-4158-9365-b95286cba796
export USER_ID=7ee00c6c-3f92-4ac0-b49e-9f690f76826e
curl -vs "http://127.0.0.1:$UVICORN_PORT/query" \
-H "content-type: application/json" \
-H "project-id: $PROJECT_ID" \
-H "user-id: $USER_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
Copyright © 2025 Open Brain Institute
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file obp_accounting_sdk-0.5.0.tar.gz.
File metadata
- Download URL: obp_accounting_sdk-0.5.0.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f845017911ac98697cca9e506db357521781a03e56c8f17cb91c4ebf3c28f5c7
|
|
| MD5 |
c2e76f2b887e1fcf7be471dd5b6ce290
|
|
| BLAKE2b-256 |
73224b1565fb5de6f499f4cf3a1042eb376702792f8677c4fdf6850e582261d9
|
Provenance
The following attestation bundles were made for obp_accounting_sdk-0.5.0.tar.gz:
Publisher:
publish-sdist.yml on openbraininstitute/accounting-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
obp_accounting_sdk-0.5.0.tar.gz -
Subject digest:
f845017911ac98697cca9e506db357521781a03e56c8f17cb91c4ebf3c28f5c7 - Sigstore transparency entry: 855254180
- Sigstore integration time:
-
Permalink:
openbraininstitute/accounting-sdk@cd8976beb6d8081c9eaecd346e1cfb78b972f717 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/openbraininstitute
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdist.yml@cd8976beb6d8081c9eaecd346e1cfb78b972f717 -
Trigger Event:
release
-
Statement type:
File details
Details for the file obp_accounting_sdk-0.5.0-py3-none-any.whl.
File metadata
- Download URL: obp_accounting_sdk-0.5.0-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82d4f1fef04a19d0ba20cbb4a4d6d13aa0858aac0c9eb9fa9e6d4080ec9315dd
|
|
| MD5 |
cb94b102f1a3eb84944d3bb2389a0392
|
|
| BLAKE2b-256 |
30712c8ff499a9cc661ecbb3c5b2c63b576cbc6feb4392624a5616321279a907
|
Provenance
The following attestation bundles were made for obp_accounting_sdk-0.5.0-py3-none-any.whl:
Publisher:
publish-sdist.yml on openbraininstitute/accounting-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
obp_accounting_sdk-0.5.0-py3-none-any.whl -
Subject digest:
82d4f1fef04a19d0ba20cbb4a4d6d13aa0858aac0c9eb9fa9e6d4080ec9315dd - Sigstore transparency entry: 855254185
- Sigstore integration time:
-
Permalink:
openbraininstitute/accounting-sdk@cd8976beb6d8081c9eaecd346e1cfb78b972f717 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/openbraininstitute
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdist.yml@cd8976beb6d8081c9eaecd346e1cfb78b972f717 -
Trigger Event:
release
-
Statement type: