obp-accounting-sdk


Nameobp-accounting-sdk JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryPython SDK for the OBP Accounting Service.
upload_time2025-07-14 11:46:21
maintainerNone
docs_urlNone
authorBlue Brain Project, EPFL, Open Brain Institute
requires_python>=3.11
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OBP Accounting SDK

[![Build status][build_status_badge]][build_status_target]
[![License][license_badge]][license_target]
[![Code coverage][coverage_badge]][coverage_target]
[![CodeQL][codeql_badge]][codeql_target]
[![PyPI][pypi_badge]][pypi_target]

## 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 = ...
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_count` is used for reservation, and it's used also for usage unless a new value is assigned to `acc_session.count`.

> [!TIP]
> The integration with the Accounting service can be disabled by setting the env variable `ACCOUNTING_DISABLED=1` before initializing the `AsyncAccountingSessionFactory` or `AccountingSessionFactory` object.

## Example

See the [Demo app](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:

```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 and user-id with:

```bash
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](CONTRIBUTING.md).

## 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](LICENSE.txt) and [AUTHORS](AUTHORS.txt) respectively.

Copyright © 2024 Blue Brain Project/EPFL

Copyright © 2025 Open Brain Institute

[build_status_badge]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/run-tox.yml/badge.svg
[build_status_target]: https://github.com/openbraininstitute/accounting-sdk/actions
[license_badge]: https://img.shields.io/pypi/l/obp-accounting-sdk
[license_target]: https://github.com/openbraininstitute/accounting-sdk/blob/main/LICENSE.txt
[coverage_badge]: https://codecov.io/github/openbraininstitute/accounting-sdk/coverage.svg?branch=main
[coverage_target]: https://codecov.io/github/openbraininstitute/accounting-sdk?branch=main
[codeql_badge]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/github-code-scanning/codeql/badge.svg
[codeql_target]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/github-code-scanning/codeql
[pypi_badge]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/publish-sdist.yml/badge.svg
[pypi_target]: https://pypi.org/project/obp-accounting-sdk/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "obp-accounting-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Blue Brain Project, EPFL, Open Brain Institute",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/2e/7f/1368500f6e26c9962f8efd4048df66d12357ca2584d40821943b96e75516/obp_accounting_sdk-0.2.1.tar.gz",
    "platform": null,
    "description": "# OBP Accounting SDK\n\n[![Build status][build_status_badge]][build_status_target]\n[![License][license_badge]][license_target]\n[![Code coverage][coverage_badge]][coverage_target]\n[![CodeQL][codeql_badge]][codeql_target]\n[![PyPI][pypi_badge]][pypi_target]\n\n## Description\n\nPython SDK for the OBP Accounting Service.\n\n## Usage\n\nThe API provides the following main classes to be used asynchronously:\n\n- `obp_accounting_sdk.AsyncAccountingSessionFactory`\n- `obp_accounting_sdk.AsyncOneshotSession`\n\nand the corresponding synchronous versions:\n\n- `obp_accounting_sdk.AccountingSessionFactory`\n- `obp_accounting_sdk.OneshotSession`\n\nThe 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:\n\n```python\nsubtype: ServiceSubtype = ...\nproj_id: UUID = ...\nuser_id: UUID = ...\nname: str | None = ...\nestimated_count: int = ...\nasync with accounting_session_factory.oneshot_session(\n    subtype=subtype,\n    proj_id=proj_id,\n    user_id=user_id,\n    name=name,\n    count=estimated_count,\n) as acc_session:\n    # actual logic\n    acc_session.count = actual_count\n    acc_session.name = actual_name\n```\n\nIn the example above:\n\n- The reservation with the accounting service happens when entering the context manager.\n- 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.\n- 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`.\n\n> [!TIP]\n> The integration with the Accounting service can be disabled by setting the env variable `ACCOUNTING_DISABLED=1` before initializing the `AsyncAccountingSessionFactory` or `AccountingSessionFactory` object.\n\n## Example\n\nSee the [Demo app](demo/app) for a working example integrated in a simple FastAPI app.\n\nIf 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:\n\n```bash\nexport ACCOUNTING_BASE_URL=http://127.0.0.1:8100\nexport UVICORN_PORT=8000\ntox -e demo\n```\n\nand call the endpoint after setting a valid project-id and user-id with:\n\n```bash\nexport PROJECT_ID=8eb248a8-672c-4158-9365-b95286cba796\nexport USER_ID=7ee00c6c-3f92-4ac0-b49e-9f690f76826e\ncurl -vs \"http://127.0.0.1:$UVICORN_PORT/query\" \\\n-H \"content-type: application/json\" \\\n-H \"project-id: $PROJECT_ID\" \\\n-H \"user-id: $USER_ID\" \\\n--data-binary @- <<EOF\n{\"input_text\": \"my query\"}\nEOF\n```\n\n## Contribution Guidelines\n\nSee [CONTRIBUTING](CONTRIBUTING.md).\n\n## Acknowledgment\n\nThe development of this software was supported by funding to the Blue Brain Project, a research center of the \u00c9cole polytechnique f\u00e9d\u00e9rale de Lausanne (EPFL), from the Swiss government\u2019s ETH Board of the Swiss Federal Institutes of Technology.\n\nFor license and authors, see [LICENSE](LICENSE.txt) and [AUTHORS](AUTHORS.txt) respectively.\n\nCopyright \u00a9 2024 Blue Brain Project/EPFL\n\nCopyright \u00a9 2025 Open Brain Institute\n\n[build_status_badge]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/run-tox.yml/badge.svg\n[build_status_target]: https://github.com/openbraininstitute/accounting-sdk/actions\n[license_badge]: https://img.shields.io/pypi/l/obp-accounting-sdk\n[license_target]: https://github.com/openbraininstitute/accounting-sdk/blob/main/LICENSE.txt\n[coverage_badge]: https://codecov.io/github/openbraininstitute/accounting-sdk/coverage.svg?branch=main\n[coverage_target]: https://codecov.io/github/openbraininstitute/accounting-sdk?branch=main\n[codeql_badge]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/github-code-scanning/codeql/badge.svg\n[codeql_target]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/github-code-scanning/codeql\n[pypi_badge]: https://github.com/openbraininstitute/accounting-sdk/actions/workflows/publish-sdist.yml/badge.svg\n[pypi_target]: https://pypi.org/project/obp-accounting-sdk/\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python SDK for the OBP Accounting Service.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/openbraininstitute/accounting-sdk",
        "Repository": "https://github.com/openbraininstitute/accounting-sdk.git",
        "Tracker": "https://github.com/openbraininstitute/accounting-sdk/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "347e9ee0b36cec042381f07f9d68240d2fd02903ae17d5dff330426d90306697",
                "md5": "58a16dae74e8c3ab0791013e5fafb0c0",
                "sha256": "e390f7afbb8eb6953a9e1ce6325656f0b8573cd71325dbda041138a107ebbe30"
            },
            "downloads": -1,
            "filename": "obp_accounting_sdk-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "58a16dae74e8c3ab0791013e5fafb0c0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 20617,
            "upload_time": "2025-07-14T11:46:20",
            "upload_time_iso_8601": "2025-07-14T11:46:20.022925Z",
            "url": "https://files.pythonhosted.org/packages/34/7e/9ee0b36cec042381f07f9d68240d2fd02903ae17d5dff330426d90306697/obp_accounting_sdk-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2e7f1368500f6e26c9962f8efd4048df66d12357ca2584d40821943b96e75516",
                "md5": "182dd7d547c1cec5660602f7a587f084",
                "sha256": "85914a32c09daa81a7616ff5027990e033ab9167b5c36d4c36ea2b491c3180fb"
            },
            "downloads": -1,
            "filename": "obp_accounting_sdk-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "182dd7d547c1cec5660602f7a587f084",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 23326,
            "upload_time": "2025-07-14T11:46:21",
            "upload_time_iso_8601": "2025-07-14T11:46:21.416242Z",
            "url": "https://files.pythonhosted.org/packages/2e/7f/1368500f6e26c9962f8efd4048df66d12357ca2584d40821943b96e75516/obp_accounting_sdk-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-14 11:46:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "openbraininstitute",
    "github_project": "accounting-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "obp-accounting-sdk"
}
        
Elapsed time: 0.76258s