# fewsats
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
This file will become your README and also the index of your
documentation.
## Developer Guide
If you are new to using `nbdev` here are some useful pointers to get you
started.
### Install fewsats_python in Development mode
``` sh
# make sure fewsats_python package is installed in development mode
$ pip install -e .
# make changes under nbs/ directory
# ...
# compile to have changes apply to fewsats_python
$ nbdev_prepare
```
## Usage
### Installation
Install latest from the GitHub
[repository](https://github.com/Fewsats/fewsats-python):
``` sh
$ pip install git+https://github.com/Fewsats/fewsats-python.git
```
or from [pypi](https://pypi.org/project/fewsats-python/)
``` sh
$ pip install fewsats
```
### Documentation
Documentation can be found hosted on this GitHub
[repository](https://github.com/Fewsats/fewsats-python)’s
[pages](https://Fewsats.github.io/fewsats-python/). Additionally you can
find package manager specific guidelines on
[conda](https://anaconda.org/Fewsats/fewsats-python) and
[pypi](https://pypi.org/project/fewsats-python/) respectively.
## How to use
The library allows you to check which payment methods you have available
and to pay for an offer.
``` python
from fewsats.core import *
from dotenv import load_dotenv
```
``` python
load_dotenv()
```
True
``` python
fs = Client()
fs.payment_methods()
```
[{'id': 5,
'last4': '4242',
'brand': 'Visa',
'exp_month': 12,
'exp_year': 2034,
'is_default': True}]
``` python
fs.balance()
```
[{'id': 15, 'balance': 9998, 'currency': 'usd'}]
`Client().balance()` returns how much balance you have in your wallet in
cents.
``` python
# Example offer from stock.l402.org
ofs = {
"offers":[
{
"amount":1,
"balance":1,
"currency":"USD",
"description":"Purchase 1 credit for API access",
"offer_id":"offer_c668e0c0",
"payment_methods":[
"lightning"
],
"title":"1 Credit Package",
"type":"top-up"
},
{
"amount":100,
"balance":120,
"currency":"USD",
"description":"Purchase 120 credits for API access",
"offer_id":"offer_97bf23f7",
"payment_methods":[
"lightning",
"coinbase_commerce"
],
"title":"120 Credits Package",
"type":"top-up"
},
{
"amount":499,
"balance":750,
"currency":"USD",
"description":"Purchase 750 credits for API access",
"offer_id":"offer_a896b13c",
"payment_methods":[
"lightning",
"coinbase_commerce",
"credit_card"
],
"title":"750 Credits Package",
"type":"top-up"
}
],
"payment_context_token":"edb53dec-28f5-4cbb-924a-20e9003c20e1",
"payment_request_url":"https://stock.l402.org/l402/payment-request",
"terms_url":"https://link-to-terms.com",
"version":"0.2.1"
}
```
``` python
from claudette import Chat, models
```
``` python
chat = Chat(models[1], sp='You are a helpful assistant that can pay offers.', tools=[fs.pay])
pr = f"Could you pay the cheapest offer using lightning {ofs}?"
r = chat.toolloop(pr, trace_func=print)
r
```
Message(id='msg_01NFdtyUuDPMMjKnqP2d1aug', content=[TextBlock(text='Certainly! I\'d be happy to help you pay for the cheapest offer using Lightning. Let\'s analyze the information you\'ve provided and proceed with the payment.\n\nThe cheapest offer from the given list is:\n\n- Amount: 1 cent (USD 0.01)\n- Balance: 1 credit\n- Currency: USD\n- Description: "Purchase 1 credit for API access"\n- Offer ID: offer_c668e0c0\n- Payment Method: Lightning\n- Title: "1 Credit Package"\n- Type: top-up\n\nNow, let\'s use the `pay` function to process this payment. I\'ll use the information you\'ve provided along with the details of the cheapest offer.', type='text'), ToolUseBlock(id='toolu_018nMWXuDMmqLBZVGsscAzAU', input={'purl': 'https://stock.l402.org/l402/payment-request', 'pct': 'edb53dec-28f5-4cbb-924a-20e9003c20e1', 'amount': 1, 'balance': 1, 'currency': 'USD', 'description': 'Purchase 1 credit for API access', 'offer_id': 'offer_c668e0c0', 'payment_methods': ['lightning'], 'title': '1 Credit Package', 'type': 'top-up'}, name='pay', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 959; Out: 426; Cache create: 0; Cache read: 0; Total: 1385)
Message(id='msg_01Fqheb9pR4YfDVDdKuRLhbC', content=[TextBlock(text='Great! The payment request has been successfully submitted. The response status code 200 OK indicates that the transaction was processed successfully.\n\nTo summarize:\n1. You\'ve purchased the "1 Credit Package" for 1 cent (USD 0.01).\n2. This package provides you with 1 credit for API access.\n3. The payment was made using the Lightning network.\n\nIs there anything else you\'d like to know about this transaction or any other assistance you need?', type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 1402; Out: 108; Cache create: 0; Cache read: 0; Total: 1510)
Great! The payment request has been successfully submitted. The response
status code 200 OK indicates that the transaction was processed
successfully.
To summarize: 1. You’ve purchased the “1 Credit Package” for 1 cent (USD
0.01). 2. This package provides you with 1 credit for API access. 3. The
payment was made using the Lightning network.
Is there anything else you’d like to know about this transaction or any
other assistance you need?
<details>
- id: `msg_01Fqheb9pR4YfDVDdKuRLhbC`
- content:
`[{'text': 'Great! The payment request has been successfully submitted. The response status code 200 OK indicates that the transaction was processed successfully.\n\nTo summarize:\n1. You\'ve purchased the "1 Credit Package" for 1 cent (USD 0.01).\n2. This package provides you with 1 credit for API access.\n3. The payment was made using the Lightning network.\n\nIs there anything else you\'d like to know about this transaction or any other assistance you need?', 'type': 'text'}]`
- model: `claude-3-5-sonnet-20240620`
- role: `assistant`
- stop_reason: `end_turn`
- stop_sequence: `None`
- type: `message`
- usage:
`{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 1402, 'output_tokens': 108}`
</details>
``` python
fs.balance()
```
[{'id': 15, 'balance': 9997, 'currency': 'usd'}]
Raw data
{
"_id": null,
"home_page": "https://github.com/Fewsats/fewsats-python",
"name": "fewsats",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "nbdev jupyter notebook python",
"author": "Jordi Montes, Pol Alvarez",
"author_email": "jordi@fewsats.com, pol@fewsats.com",
"download_url": "https://files.pythonhosted.org/packages/34/15/02d8c357d2b0754cb26890fa202a9ea367cc66618b63047a911e0749efd6/fewsats-0.0.7.tar.gz",
"platform": null,
"description": "# fewsats\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nThis file will become your README and also the index of your\ndocumentation.\n\n## Developer Guide\n\nIf you are new to using `nbdev` here are some useful pointers to get you\nstarted.\n\n### Install fewsats_python in Development mode\n\n``` sh\n# make sure fewsats_python package is installed in development mode\n$ pip install -e .\n\n# make changes under nbs/ directory\n# ...\n\n# compile to have changes apply to fewsats_python\n$ nbdev_prepare\n```\n\n## Usage\n\n### Installation\n\nInstall latest from the GitHub\n[repository](https://github.com/Fewsats/fewsats-python):\n\n``` sh\n$ pip install git+https://github.com/Fewsats/fewsats-python.git\n```\n\nor from [pypi](https://pypi.org/project/fewsats-python/)\n\n``` sh\n$ pip install fewsats\n```\n\n### Documentation\n\nDocumentation can be found hosted on this GitHub\n[repository](https://github.com/Fewsats/fewsats-python)\u2019s\n[pages](https://Fewsats.github.io/fewsats-python/). Additionally you can\nfind package manager specific guidelines on\n[conda](https://anaconda.org/Fewsats/fewsats-python) and\n[pypi](https://pypi.org/project/fewsats-python/) respectively.\n\n## How to use\n\nThe library allows you to check which payment methods you have available\nand to pay for an offer.\n\n``` python\nfrom fewsats.core import * \nfrom dotenv import load_dotenv\n```\n\n``` python\nload_dotenv()\n```\n\n True\n\n``` python\nfs = Client()\nfs.payment_methods()\n```\n\n [{'id': 5,\n 'last4': '4242',\n 'brand': 'Visa',\n 'exp_month': 12,\n 'exp_year': 2034,\n 'is_default': True}]\n\n``` python\nfs.balance()\n```\n\n [{'id': 15, 'balance': 9998, 'currency': 'usd'}]\n\n`Client().balance()` returns how much balance you have in your wallet in\ncents.\n\n``` python\n# Example offer from stock.l402.org\nofs = {\n \"offers\":[\n {\n \"amount\":1,\n \"balance\":1,\n \"currency\":\"USD\",\n \"description\":\"Purchase 1 credit for API access\",\n \"offer_id\":\"offer_c668e0c0\",\n \"payment_methods\":[\n \"lightning\"\n ],\n \"title\":\"1 Credit Package\",\n \"type\":\"top-up\"\n },\n {\n \"amount\":100,\n \"balance\":120,\n \"currency\":\"USD\",\n \"description\":\"Purchase 120 credits for API access\",\n \"offer_id\":\"offer_97bf23f7\",\n \"payment_methods\":[\n \"lightning\",\n \"coinbase_commerce\"\n ],\n \"title\":\"120 Credits Package\",\n \"type\":\"top-up\"\n },\n {\n \"amount\":499,\n \"balance\":750,\n \"currency\":\"USD\",\n \"description\":\"Purchase 750 credits for API access\",\n \"offer_id\":\"offer_a896b13c\",\n \"payment_methods\":[\n \"lightning\",\n \"coinbase_commerce\",\n \"credit_card\"\n ],\n \"title\":\"750 Credits Package\",\n \"type\":\"top-up\"\n }\n ],\n \"payment_context_token\":\"edb53dec-28f5-4cbb-924a-20e9003c20e1\",\n \"payment_request_url\":\"https://stock.l402.org/l402/payment-request\",\n \"terms_url\":\"https://link-to-terms.com\",\n \"version\":\"0.2.1\"\n}\n```\n\n``` python\nfrom claudette import Chat, models\n```\n\n``` python\nchat = Chat(models[1], sp='You are a helpful assistant that can pay offers.', tools=[fs.pay])\npr = f\"Could you pay the cheapest offer using lightning {ofs}?\"\nr = chat.toolloop(pr, trace_func=print)\nr\n```\n\n Message(id='msg_01NFdtyUuDPMMjKnqP2d1aug', content=[TextBlock(text='Certainly! I\\'d be happy to help you pay for the cheapest offer using Lightning. Let\\'s analyze the information you\\'ve provided and proceed with the payment.\\n\\nThe cheapest offer from the given list is:\\n\\n- Amount: 1 cent (USD 0.01)\\n- Balance: 1 credit\\n- Currency: USD\\n- Description: \"Purchase 1 credit for API access\"\\n- Offer ID: offer_c668e0c0\\n- Payment Method: Lightning\\n- Title: \"1 Credit Package\"\\n- Type: top-up\\n\\nNow, let\\'s use the `pay` function to process this payment. I\\'ll use the information you\\'ve provided along with the details of the cheapest offer.', type='text'), ToolUseBlock(id='toolu_018nMWXuDMmqLBZVGsscAzAU', input={'purl': 'https://stock.l402.org/l402/payment-request', 'pct': 'edb53dec-28f5-4cbb-924a-20e9003c20e1', 'amount': 1, 'balance': 1, 'currency': 'USD', 'description': 'Purchase 1 credit for API access', 'offer_id': 'offer_c668e0c0', 'payment_methods': ['lightning'], 'title': '1 Credit Package', 'type': 'top-up'}, name='pay', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=In: 959; Out: 426; Cache create: 0; Cache read: 0; Total: 1385)\n Message(id='msg_01Fqheb9pR4YfDVDdKuRLhbC', content=[TextBlock(text='Great! The payment request has been successfully submitted. The response status code 200 OK indicates that the transaction was processed successfully.\\n\\nTo summarize:\\n1. You\\'ve purchased the \"1 Credit Package\" for 1 cent (USD 0.01).\\n2. This package provides you with 1 credit for API access.\\n3. The payment was made using the Lightning network.\\n\\nIs there anything else you\\'d like to know about this transaction or any other assistance you need?', type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 1402; Out: 108; Cache create: 0; Cache read: 0; Total: 1510)\n\nGreat! The payment request has been successfully submitted. The response\nstatus code 200 OK indicates that the transaction was processed\nsuccessfully.\n\nTo summarize: 1. You\u2019ve purchased the \u201c1 Credit Package\u201d for 1 cent (USD\n0.01). 2. This package provides you with 1 credit for API access. 3. The\npayment was made using the Lightning network.\n\nIs there anything else you\u2019d like to know about this transaction or any\nother assistance you need?\n\n<details>\n\n- id: `msg_01Fqheb9pR4YfDVDdKuRLhbC`\n- content:\n `[{'text': 'Great! The payment request has been successfully submitted. The response status code 200 OK indicates that the transaction was processed successfully.\\n\\nTo summarize:\\n1. You\\'ve purchased the \"1 Credit Package\" for 1 cent (USD 0.01).\\n2. This package provides you with 1 credit for API access.\\n3. The payment was made using the Lightning network.\\n\\nIs there anything else you\\'d like to know about this transaction or any other assistance you need?', 'type': 'text'}]`\n- model: `claude-3-5-sonnet-20240620`\n- role: `assistant`\n- stop_reason: `end_turn`\n- stop_sequence: `None`\n- type: `message`\n- usage:\n `{'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 0, 'input_tokens': 1402, 'output_tokens': 108}`\n\n</details>\n\n``` python\nfs.balance()\n```\n\n [{'id': 15, 'balance': 9997, 'currency': 'usd'}]\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Python SDK for Fewsats",
"version": "0.0.7",
"project_urls": {
"Homepage": "https://github.com/Fewsats/fewsats-python"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2d85cba77d4c9a204cdd248bfa33f1c23516bd802c6b37af5687f182280af38c",
"md5": "27e00d4905da54e09d1d4391a88ad217",
"sha256": "8710de096237ce662741df7ea98346f794887d8d2160d88fbf32a8aa6853a4e5"
},
"downloads": -1,
"filename": "fewsats-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "27e00d4905da54e09d1d4391a88ad217",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 11236,
"upload_time": "2024-12-20T13:26:52",
"upload_time_iso_8601": "2024-12-20T13:26:52.764671Z",
"url": "https://files.pythonhosted.org/packages/2d/85/cba77d4c9a204cdd248bfa33f1c23516bd802c6b37af5687f182280af38c/fewsats-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "341502d8c357d2b0754cb26890fa202a9ea367cc66618b63047a911e0749efd6",
"md5": "292e8a38bc58d717883b96041046e0b9",
"sha256": "4d4d506a7cd966460b7ad3b54da9617ba56a748db2e3f6152037338e5c91dae7"
},
"downloads": -1,
"filename": "fewsats-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "292e8a38bc58d717883b96041046e0b9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 12114,
"upload_time": "2024-12-20T13:26:53",
"upload_time_iso_8601": "2024-12-20T13:26:53.802094Z",
"url": "https://files.pythonhosted.org/packages/34/15/02d8c357d2b0754cb26890fa202a9ea367cc66618b63047a911e0749efd6/fewsats-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-20 13:26:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Fewsats",
"github_project": "fewsats-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fewsats"
}