Name | opencredit JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Credit management for SaaS |
upload_time | 2024-04-14 23:57:21 |
maintainer | None |
docs_url | None |
author | Patrick Barker |
requires_python | <4.0,>=3.10 |
license | Apache 2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<!-- PROJECT LOGO -->
<br />
<p align="center">
<!-- <a href="https://github.com/agentsea/skillpacks">
<img src="https://project-logo.png" alt="Logo" width="80">
</a> -->
<div style="display: flex; align-items: center; justify-content: center;">
<h1>OpenCredit</h1>
<img src="https://icons.iconarchive.com/icons/ph03nyx/super-mario/256/Retro-Coin-icon.png" alt="SurfDino Logo" width="50" height="50" style="border-radius: 20px; margin-left: 10px; margin-bottom: 20px;">
</div>
<p align="center">
Credit management for pay-per-use applications
<br />
<a href="https://github.com/agentsea/opencredit"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/agentsea/opencredit">View Demo</a>
·
<a href="https://github.com/agentsea/opencredit/issues">Report Bug</a>
·
<a href="https://github.com/agentsea/opencredit/issues">Request Feature</a>
</p>
<br>
</p>
## Installation
```python
pip install opencredit
```
## Usage
### Connect
Get an API key
```sh
opencredit login https://foo.bar
```
Connect the Python client
```python
import os
from opencredit import Client
client = Client(addr="https://foo.bar", api_key=os.getenv("OPENCREDIT_API_KEY"))
```
### Define a credit type
Define a credit type for your application.
```python
client.create_credit(
name="MyAppCredit",
description="Credit for my awesome application"
user_minimum=-20.00,
user_maximum=10000.00,
user_start=10.00,
)
```
`user_minimum` is the default minimum credit a user can have.
`user_maximum` is the default maximum credit a user can have.
`user_start` is the default starting credit a user has.
### Per user configuration
Add credits for a user
```python
client.add_user_credit(credit="MyAppCredit", email="dolores@agentsea.ai", amount=100.00)
```
Set per user limits
```python
client.set_user_limits(
credit="MyAppCredit",
email="dolores@agentsea.ai",
user_minimum=-20.00,
user_maximum=10000.00,
user_start=200.00
)
```
Set automatic top up
```python
client.set_user_topup(
credit="MyAppCredit",
email="dolores@agentsea.ai",
min_balance=5.00,
topup_amount=10.00
)
```
### Use credits
See how many credits the user currently has
```python
client.get_balance(credit="MyAppCredit", email="dolores@agentsea.ai")
```
Create a meter to charge credits based on type of usage
```python
client.create_meter(
credit="MyAppCredit",
name="llm_tokens",
unit="token",
cost=0.0004,
description="LLM generated tokens"
)
```
Tik the meter to use credits
```python
client.tik_meter(name="llm_tokens", amount=200, email="dolores@agentsea.ai")
```
### Reporting
Get a report of credit usage
```python
client.get_report(
credit="MyAppCredit",
email="dolores@agentsea.ai",
start="2020-01-01",
end="2020-01-31"
)
```
## Hosting a credit server
Run locally
```python
from opencredit import Server
server = Server(backend="postgres")
server.serve()
```
Run on Kubernetes
```sh
helm install open-credit-server --set backend=postgres open-credit
```
Raw data
{
"_id": null,
"home_page": null,
"name": "opencredit",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Patrick Barker",
"author_email": "patrickbarkerco@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/42/6f/420ca005305e132977e3beb098b4084d3d15703a20cc1e424602ce6df139/opencredit-0.1.1.tar.gz",
"platform": null,
"description": "<!-- PROJECT LOGO -->\n<br />\n<p align=\"center\">\n <!-- <a href=\"https://github.com/agentsea/skillpacks\">\n <img src=\"https://project-logo.png\" alt=\"Logo\" width=\"80\">\n </a> -->\n\n <div style=\"display: flex; align-items: center; justify-content: center;\">\n <h1>OpenCredit</h1>\n <img src=\"https://icons.iconarchive.com/icons/ph03nyx/super-mario/256/Retro-Coin-icon.png\" alt=\"SurfDino Logo\" width=\"50\" height=\"50\" style=\"border-radius: 20px; margin-left: 10px; margin-bottom: 20px;\">\n </div>\n <p align=\"center\">\n Credit management for pay-per-use applications\n <br />\n <a href=\"https://github.com/agentsea/opencredit\"><strong>Explore the docs \u00bb</strong></a>\n <br />\n <br />\n <a href=\"https://github.com/agentsea/opencredit\">View Demo</a>\n \u00b7\n <a href=\"https://github.com/agentsea/opencredit/issues\">Report Bug</a>\n \u00b7\n <a href=\"https://github.com/agentsea/opencredit/issues\">Request Feature</a>\n </p>\n <br>\n</p>\n\n## Installation\n\n```python\npip install opencredit\n```\n\n## Usage\n\n### Connect\n\nGet an API key\n\n```sh\nopencredit login https://foo.bar\n```\n\nConnect the Python client\n\n```python\nimport os\nfrom opencredit import Client\n\nclient = Client(addr=\"https://foo.bar\", api_key=os.getenv(\"OPENCREDIT_API_KEY\"))\n```\n\n### Define a credit type\n\nDefine a credit type for your application.\n\n```python\nclient.create_credit(\n name=\"MyAppCredit\",\n description=\"Credit for my awesome application\"\n user_minimum=-20.00,\n user_maximum=10000.00,\n user_start=10.00,\n )\n```\n\n`user_minimum` is the default minimum credit a user can have. \n`user_maximum` is the default maximum credit a user can have. \n`user_start` is the default starting credit a user has.\n\n### Per user configuration\n\nAdd credits for a user\n\n```python\nclient.add_user_credit(credit=\"MyAppCredit\", email=\"dolores@agentsea.ai\", amount=100.00)\n```\n\nSet per user limits\n\n```python\nclient.set_user_limits(\n credit=\"MyAppCredit\",\n email=\"dolores@agentsea.ai\",\n user_minimum=-20.00,\n user_maximum=10000.00,\n user_start=200.00\n )\n```\n\nSet automatic top up\n\n```python\nclient.set_user_topup(\n credit=\"MyAppCredit\",\n email=\"dolores@agentsea.ai\",\n min_balance=5.00,\n topup_amount=10.00\n )\n```\n\n### Use credits\n\nSee how many credits the user currently has\n\n```python\nclient.get_balance(credit=\"MyAppCredit\", email=\"dolores@agentsea.ai\")\n```\n\nCreate a meter to charge credits based on type of usage\n\n```python\nclient.create_meter(\n credit=\"MyAppCredit\",\n name=\"llm_tokens\",\n unit=\"token\",\n cost=0.0004,\n description=\"LLM generated tokens\"\n )\n```\n\nTik the meter to use credits\n\n```python\nclient.tik_meter(name=\"llm_tokens\", amount=200, email=\"dolores@agentsea.ai\")\n```\n\n### Reporting\n\nGet a report of credit usage\n\n```python\nclient.get_report(\n credit=\"MyAppCredit\",\n email=\"dolores@agentsea.ai\",\n start=\"2020-01-01\",\n end=\"2020-01-31\"\n )\n```\n\n## Hosting a credit server\n\nRun locally\n\n```python\nfrom opencredit import Server\n\nserver = Server(backend=\"postgres\")\n\nserver.serve()\n```\n\nRun on Kubernetes\n\n```sh\nhelm install open-credit-server --set backend=postgres open-credit\n```\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Credit management for SaaS",
"version": "0.1.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c0f15cb7f29fa1990e623f1572f5af78423dc8649fe0d587758f1fa1e3443bc2",
"md5": "7a931846d5d470885c7d68503a26b036",
"sha256": "774d37fb5b8788fa52ef83abeca1c43fa3209ed3b5660bd2d013a70f45d30062"
},
"downloads": -1,
"filename": "opencredit-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7a931846d5d470885c7d68503a26b036",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 19091,
"upload_time": "2024-04-14T23:57:20",
"upload_time_iso_8601": "2024-04-14T23:57:20.192400Z",
"url": "https://files.pythonhosted.org/packages/c0/f1/5cb7f29fa1990e623f1572f5af78423dc8649fe0d587758f1fa1e3443bc2/opencredit-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "426f420ca005305e132977e3beb098b4084d3d15703a20cc1e424602ce6df139",
"md5": "a9a4f56f410ad1b962c5c3a6e57c488c",
"sha256": "71ec580c6d97121ebd76c595f6f9b228c5b02eb24a6e4235a7bbcbe8f15ef0f9"
},
"downloads": -1,
"filename": "opencredit-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a9a4f56f410ad1b962c5c3a6e57c488c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 15085,
"upload_time": "2024-04-14T23:57:21",
"upload_time_iso_8601": "2024-04-14T23:57:21.804884Z",
"url": "https://files.pythonhosted.org/packages/42/6f/420ca005305e132977e3beb098b4084d3d15703a20cc1e424602ce6df139/opencredit-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-14 23:57:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "opencredit"
}