Python SDK for the Bitnob"s API
Project description
Bitnob
This is a Python package for easy integration of Bitnob For Business API for various applications from Bitnob.
Getting started
Requirements
This package requires Python 3.6+
Installation
pip install bitnob
Usage
This SDK can be used both for Bitnob Sandbox and Production API.
Setting ENV KEYS
For sucessfully running of the SDK; the BITNOB_API_KEY
must be set.
Now this will throw a BitnobBadKeyError
error, if you do not set it as an environment variable, when initiatizing a function.
By default the SDK assumes that you are currently working on production, and your BITNOB_API_KEY
must be a production-grade secret key.
To run on sandbox(development mode), set BITNOB_PRODUCTION=false
as an environment variable.
Instantiate The Bitnob Functions
Before making use of any bitnob functions, it should be instantiated. Below is a demonstration:
from bitnob import Lightning
lightning = Lightning()
customer = Customer()
onchain = Onchain()
wallet = Wallets()
Customers
- To manage customers in your application, instantiate a new
Customer
class.- The following functions are available:
- create_customer
- get_customer_by_email
- get_customer
- update_customer
- The following functions are available:
Lightning
- To create Lightning Transactions, instantiate a new
Lightning
class.- The following functions are available:
- create_invoice
- pay_invoice
- initiate_payment
- decode_payment_request
- get_invoice
- The following functions are available:
Full Lightning Workflow
from bitnob import Lightning
lightning = Lightning()
payload = {
"customerEmail": "bernard@bitnob.com",
"description": "Enjoy Life!",
"tokens": 300,
"expires_at": "24h",
"private": false,
"is_including_private_channels": false,
"is_fallback_included": true,
}
# Create a lightning invoice
new_ln_invoice = lightning.create_invoice(payload)
Onchain
- To create Onchain Transactions, instantiate a new
Onchain
class.- The following functions are available:
- send_bitcoin
- generate_address
- list_addresses
- The following functions are available:
Full Onchain Transaction Workflow
from bitnob import Onchain
on_chain = Onchain()
payload = {
"customerEmail": "bernard@bitnob.com",
"reference": "txt-ref-09fdcsf-7658dcgfh-84738pokli",
"satoshis": 30000,
"address": "btcjshlidlsidskdslisidsdosilsdmxksjsjldksossjoioidjifkji.zjijsi",
"description": "Go buy your momma a house!",
"priorityLevel": "priority"
}
# Send bitcoin using onchain
new_onchain = on_chain.send_bitcoin(payload)
Wallets
- To get wallets information, simply follow the instruction at the beginning of this sub-heading and instantiate a new
Wallets
class.- The following functions are available:
- wallet_detail
- get_transaction
- list_transactions
- The following functions are available:
Webhook Authentication
- The Bitnob SDK comes with a function that enables your business authenticate events sent to your webhook. It is advised to authenticate all requests sent to your endpoint to avoid fake transactions.
Usage
from fastapi import FastAPI
from bitnob import webhook_authenication
app = FastAPI()
@app.post("/webhook_endpoint/")
async def webhook_event_handler(event):
if webhook_authenication(event):
#Handle event
#return 200
else:
#do nothing or throw error
Development
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/bitnob/bitnob_python_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct. Simply create a new branch and raise a Pull Request, we would review and merge.
License
The package is available as open source under the terms of the BSD License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bitnob-1.3.2.tar.gz
.
File metadata
- Download URL: bitnob-1.3.2.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 915a8418e994e9f2debc54378cab7ad9fdb9d4a3642174ed385d91649765ce72 |
|
MD5 | 7cceb674c9c0ca825a3a4e5340bbffaa |
|
BLAKE2b-256 | f6be37538f22623da7149c72788f5964f5c005ccf7165eb09eb47b473da3e1d6 |
File details
Details for the file bitnob-1.3.2-py3-none-any.whl
.
File metadata
- Download URL: bitnob-1.3.2-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 088b176bb2aafa118c71de71752bbb5d9491b7adcba95cc51add55524231acf7 |
|
MD5 | e7b110b61e211d0dc8b48f451791ee01 |
|
BLAKE2b-256 | 39a7e6fb97312d1449c9046d79afc415855cad90bc5f74bc3c302538179452a6 |