obp-accounting-sdk


Nameobp-accounting-sdk JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryPython SDK for the OBP Accounting Service.
upload_time2024-08-28 12:52:13
maintainerNone
docs_urlNone
authorBlue Brain Project, EPFL
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 = ...
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](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](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


[build_status_badge]: https://github.com/BlueBrain/obp-accounting-sdk/actions/workflows/run-tox.yml/badge.svg
[build_status_target]: https://github.com/BlueBrain/obp-accounting-sdk/actions
[license_badge]: https://img.shields.io/pypi/l/obp-accounting-sdk
[license_target]: https://github.com/BlueBrain/obp-accounting-sdk/blob/main/LICENSE.txt
[coverage_badge]: https://codecov.io/github/BlueBrain/obp-accounting-sdk/coverage.svg?branch=main
[coverage_target]: https://codecov.io/github/BlueBrain/obp-accounting-sdk?branch=main
[codeql_badge]: https://github.com/BlueBrain/obp-accounting-sdk/actions/workflows/github-code-scanning/codeql/badge.svg
[codeql_target]: https://github.com/BlueBrain/obp-accounting-sdk/actions/workflows/github-code-scanning/codeql
[pypi_badge]: https://github.com/BlueBrain/obp-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",
    "author_email": "Gianluca Ficarelli <gianluca.ficarelli@epfl.ch>",
    "download_url": "https://files.pythonhosted.org/packages/8a/33/2852b53834df90fdecf5ab4dd8ac102bf8b48602d64a7029dec150a0429c/obp_accounting_sdk-0.1.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\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 = ...\nestimated_count: int = ...\nasync with accounting_session_factory.oneshot_session(\n    subtype=subtype,\n    proj_id=proj_id,\n    count=estimated_count,\n) as acc_session:\n    # actual logic\n    acc_session.count = actual_count\n```\n\nIn the example above:\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\n## Example\n\nSee the [Demo app](demo/app) for a working example integrated in a simple FastAPI app.\n\nIf you installed `tox`, 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 with:\n\n```bash\nexport PROJECT_ID=8eb248a8-672c-4158-9365-b95286cba796\ncurl -vs \"http://127.0.0.1:$UVICORN_PORT/query\" \\\n-H \"content-type: application/json\" \\\n-H \"project-id: $PROJECT_ID\" \\\n--data-binary @- <<EOF\n{\"input_text\": \"my query\"}\nEOF\n```\n\nContribution Guidelines\n-----------------------\n\nSee [CONTRIBUTING](CONTRIBUTING.md).\n\n\nAcknowledgment\n--------------\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\n\n[build_status_badge]: https://github.com/BlueBrain/obp-accounting-sdk/actions/workflows/run-tox.yml/badge.svg\n[build_status_target]: https://github.com/BlueBrain/obp-accounting-sdk/actions\n[license_badge]: https://img.shields.io/pypi/l/obp-accounting-sdk\n[license_target]: https://github.com/BlueBrain/obp-accounting-sdk/blob/main/LICENSE.txt\n[coverage_badge]: https://codecov.io/github/BlueBrain/obp-accounting-sdk/coverage.svg?branch=main\n[coverage_target]: https://codecov.io/github/BlueBrain/obp-accounting-sdk?branch=main\n[codeql_badge]: https://github.com/BlueBrain/obp-accounting-sdk/actions/workflows/github-code-scanning/codeql/badge.svg\n[codeql_target]: https://github.com/BlueBrain/obp-accounting-sdk/actions/workflows/github-code-scanning/codeql\n[pypi_badge]: https://github.com/BlueBrain/obp-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.1.1",
    "project_urls": {
        "Homepage": "https://github.com/BlueBrain/obp-accounting-sdk",
        "Repository": "https://github.com/BlueBrain/obp-accounting-sdk.git",
        "Tracker": "https://github.com/BlueBrain/obp-accounting-sdk/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf373c85e055e33b6d1792fbed86ee25fb4844d192f72c4daecd4816a36b91eb",
                "md5": "72ba85d18c60cbb51ccb7033cd6e60da",
                "sha256": "f12daab355e12eae0740bef93080af63129cf9e2337901d0cb8ae4beca46009c"
            },
            "downloads": -1,
            "filename": "obp_accounting_sdk-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "72ba85d18c60cbb51ccb7033cd6e60da",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 14127,
            "upload_time": "2024-08-28T12:52:12",
            "upload_time_iso_8601": "2024-08-28T12:52:12.506221Z",
            "url": "https://files.pythonhosted.org/packages/bf/37/3c85e055e33b6d1792fbed86ee25fb4844d192f72c4daecd4816a36b91eb/obp_accounting_sdk-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8a332852b53834df90fdecf5ab4dd8ac102bf8b48602d64a7029dec150a0429c",
                "md5": "7f6622ff3dd3db710bc548c30f05eb70",
                "sha256": "ca61805d7ec08c5e666c6b818d2fd35d2b7e61e9d79c6745caee00f09ef5f272"
            },
            "downloads": -1,
            "filename": "obp_accounting_sdk-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7f6622ff3dd3db710bc548c30f05eb70",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 18499,
            "upload_time": "2024-08-28T12:52:13",
            "upload_time_iso_8601": "2024-08-28T12:52:13.737773Z",
            "url": "https://files.pythonhosted.org/packages/8a/33/2852b53834df90fdecf5ab4dd8ac102bf8b48602d64a7029dec150a0429c/obp_accounting_sdk-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-28 12:52:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BlueBrain",
    "github_project": "obp-accounting-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "obp-accounting-sdk"
}
        
Elapsed time: 0.87115s