https://github.com/bluebrain/obp-accounting-sdk

Python SDK for the OBP Accounting Service

https://github.com/bluebrain/obp-accounting-sdk

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

Python SDK for the OBP Accounting Service

Basic Info
  • Host: GitHub
  • Owner: BlueBrain
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 25.4 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 2
Archived
Created almost 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog Contributing License Authors

README.md

[!WARNING] The Blue Brain Project concluded in December 2024, so development has ceased under the BlueBrain GitHub organization. Future development will take place at: https://github.com/openbraininstitute/accounting-sdk

obp-accounting-sdk

Build status License Code coverage CodeQL PyPI

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:

python 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 to acc_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:

bash 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:

bash 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

Owner

  • Name: The Blue Brain Project
  • Login: BlueBrain
  • Kind: organization
  • Email: bbp.opensource@epfl.ch
  • Location: Geneva, Switzerland

Open Source Software produced and used by the Blue Brain Project

GitHub Events

Total
  • Push event: 1
  • Fork event: 1
Last Year
  • Push event: 1
  • Fork event: 1

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: about 1 hour
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 1.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: about 1 hour
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 1.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • GianlucaFicarelli (4)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

pyproject.toml pypi
  • httpx *
.github/workflows/publish-sdist.yml actions
  • actions/checkout v4 composite
  • actions/download-artifact v4 composite
  • actions/upload-artifact v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite
.github/workflows/run-tox.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
  • codecov/codecov-action v4 composite