GithubHelp home page GithubHelp logo

pybry's Introduction

PyBRY, a Python API wrapper for lbrynet and lbrycrd

License: MIT

PyBry is a Python 3 wrapper for the lbrynet and lbrycrd daemons from the LBRY project. It allows calling the methods of these daemons inside Python programs.

Installation

You must have the LBRY Desktop application or the lbrynet client. Get them from lbry.com/get.

The lbrycrd blockchain can be downloaded from the lbrycrd repository.

Cloning the repository

Clone the repository into a user-writeable directory:

git clone https://github.com/osilkin98/PyBRY

Make

Change into the newly created repository, and run the Makefile:

cd PyBRY/
make

The generated API wrapper will be composed of the newly created pybry/ directory, and the files contained in there. The entire directory is a Python package which can be installed in the Python path.

By default the lbrynet API wrapper is created from the files in the template/ directory, and the docs/api.json file. These are equivalent:

make
make build_local

To create the latest wrapper you must use the latest api.json directly from the lbry-sdk repository. This can be done with a single instruction:

make build_online

However, if the online JSON file has errors, the generated wrapper may also contain syntax errors, and it will not work when used in a Python program. In this case, clean the generated API, and use the local api.json that is guaranteed to work:

make clean
make

Read the docs/README.md file for more information.

In contrast to the lbrynet wrapper, the lbrycrd API wrapper is not created from any JSON file, as at the moment (2021) there is no JSON document describing all methods from lbrycrd. This wrapper is mostly a copy from its template in the template/ directory.

To use the new wrapper code, copy the pybry/ directory, and place it inside a site-packages directory that is searched by Python. This can be in the user's home directory,

/home/user/.local/lib/python3.8/site-packages/pybry

or in a system-wide directory:

/usr/local/lib/python3.8/dist-packages/pybry
/usr/lib/python3/dist-packages/pybry

You can also modify the PYTHONPATH environmental variable to include the parent directory where pybry is located:

PYTHONPATH=/opt/git/PyBRY:$PYTHONPATH

Setuptools

Instead of using the Makefile, we can use setuptools as well:

python3 setup.py build_local
python3 setup.py build_online
python3 setup.py clean
python3 setup.py clean --all

Normally setuptools will create a build/ directory where a copy of the package will be placed.

Older installation

There is a pybry package available in PyPI. However, this corresponds to the 1.6.4 version, and thus it is not up to date.

pip install --user pybry

Usage

API for lbrynet

Make sure the lbrynet daemon is running either by launching the full LBRY Desktop application, or by starting the console lbrynet program.

lbrynet start

Using the generated wrapper

The wrapper generates all functions from the lbrynet documentation, and produces documented Python code.

Import the library, initialize the main class, and then call its methods, which have the same name and arguments as described in the documentation.

import pybry
lbry = pybry.LbrydApi()
response1 = lbry.claim_search(name="LBRYPlaylists")
response2 = lbry.support_list()
response3 = lbry.file_list(sort="claim_name", reverse=True)

Since the code is properly documented, if you ask for its documentation in an integrated development environment (IDE), or if you go to read it for yourself, it'll appear like this:

response = lbry.account_balance()

Return the balance of an account
Params:
account_idIf provided only the balance for this account will be given (Optional)
addressIf provided only the balance for this address will be given (Optional)
include_unconfirmedInclude unconfirmed (Optional)
Returns:
(decimal) amount of lbry credits in wallet(decimal) amount of lbry credits in wallet

Note that at the moment the return information is not available, as the API JSON files don't contain this information in a standardized way.

Calling the API manually

All the wrapper code does is make requests to the running lbrynet daemon. Therefore, if there is no proper wrapper for a particular method (because it was generated by an outdated api.json, for example), a simple message can be sent to the daemon just like with using the requests library or curl.

method = "claim_search"
message = {"name": "LBRYPlaylists"}

response = lbry.call(method, message)

API for lbrycrd

Initialize the daemon with a username and password and send messages just like with using the requests library.

import pybry
lbrycrd = pybry.LbrycrdApi("username", "password")

method = "wallet_unlock"
message = {"wallet_username", "wallet_password"}
response = lbrycrd.call(method, message)

pybry's People

Contributors

belikor avatar osilkin98 avatar

Forkers

sensoricatech

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.