New LightHive release: 0.3.0

in HiveDevs3 years ago (edited)


Lighthive documentation


A new version of Lighthive is pushed to the Python package index with the tag 0.3.0 . As usual, pip install lighthive --upgrade is enough to get the latest version.

As a client, it's important to select the closest/fastest node to your server.

For example, if your script/app runs in a server at Europe, it makes sense to connect one of the Europe nodes. Same logic applies for the different parts of the world; for Asia, US, etc.

Now, we have that selection automatic at Lighthive; If you pass automatic_node_selection flag True to the Client instance, nodes will be sorted by the response time.

Related measurement calls are done via asyncio and httpx, concurrently. This speeds up the process, however, it still takes some time to request all nodes. That's why automatic_node_selection is disabled by default.


Check out the docs

Example usage:


import logging

from lighthive.client import Client
c = Client(loglevel=logging.DEBUG, automatic_node_selection=True)

Logging output:


2021-12-30 17:20:28,515 lighthive    INFO     Measurements: 
https://rpc.ausbit.dev: 0.12 [s]
https://api.openhive.network: 0.12 [s]
https://hive-api.arcange.eu: 0.12 [s]
https://hived.emre.sh: 0.14 [s]
https://api.deathwing.me: 0.15 [s]
https://rpc.ecency.com: 0.16 [s]
https://api.hive.blue: 0.19 [s]
https://api.pharesim.me: 0.28 [s]
https://api.hive.blog: 0.46 [s]
https://techcoderx.com: 0.77 [s]

2021-12-30 17:20:28,516 lighthive    INFO     Automatic node selection took  0.81 seconds.
2021-12-30 17:20:28,516 lighthive    INFO     Node set as https://rpc.ausbit.dev

Also updated the default node list with the up to date public nodes. See the related pull request.

Sort:  

lighthive is a light python client to interact with the HIVE blockchain. It’s simple and stupid.

This is my spirit animal ;)

Great work and thank you to everyone involved in this, I love the fact you are putting time and energy into making it easier for people to develop apps!

Great work, would love to see if anyone starts the Utopian again...

@acidyo mentioned they were curating dev posts, a while ago. maybe that's not the correct community, though. :)

We could include this one I suppose, the other has had lack of posts. Will check with some of our curators.

I think, that's already rewarded enough; I was talking in general, rewarding the dev posts like Utopian did back in the day.

Ah okay yeah, well the former isn't an issue as we make sure to mainly reward underrewarded posts. Was just thinking of combining the curation efforts with the programming community so we'd have something to curate.

ah, ok. got it. interpreted the "this one" in a different way at first glance.

cool. 🤘

haha ahh what ever happened to @utopianio ? @utopian-io ?

yep me too

I am not talking about rewarding only, when we have Utopian-io, there were so many people who were actually creating something or the other, new things you know...which is actually lacking now.

This is really awesome and a work well-done. I appreciate every part of it, keep up the good work moving.

Looking good :) Great to see our discussion sped the development of this.

Little idea for a transmitter update:

Instead of getting the prices of each exchange and then the average of those, it would be more precise to average by volume...

As in: If there is little trading depth, the price should not have the same impact as that of the larger exchange with more volume.

there is already an outlier detection algorithm in place. E.g: if a market reports 1.5, while the others reports 1, the market reports 1.5 is excluded from the calculation.

This helps on certain situatations. It would be also nice to have the volume is a part of price calculation, however, do we really need it?

Is there a case/time frame that we report a very different price because of this? If that's the case, then this feature can go high in the priority list.

Nah, this should not be high on the priority list...
Just an idea to set your tool apart from the others maybe.

yeah, I hear you. It's nice to have for sure. I'll take a look when I have time.

gif_good_job_58.gif

First off; I am not a programmer, but have been trying to learn a little python stuff.
When I type pip install lighthive --upgrade in the terminal window of my Raspberry Pi I get and error:

ERROR: No matching distribution found for lighthive
WARNING: pip is configured with locations that require TLS/SSL, 
however the ssl module in Python is not available.```

Any idea on how I can install lighthive? I know you are likely real busy right now, so I can wait for a response, it is not earth shattering to me if I can not get it to work.

no problem. lighthive is Python3.6 and greater versions. Seems like your default Python installation at your RPI is Python2.

You can try sudo pip3 install lighthive. If Python3 is installed in your RPI, that would do the job. Otherwise, you need Python3 first.

Python 3.10.1 installed, and lighthive installed with it thanks for the help, now to try and learn.

Okay, thanks I am working on updating python to 3.10.1, I figured it was due to python version.

Nice and good development

Wow! It good to see new developments 👍

I need to have a look at this... if this can be put in front of the RPC calls hive-engine nodes do, this would solve some of the problems I had because of the long distance. Now I have a HIVE local node too, but this will probably help too.

Cheers

The module is here: https://github.com/emre/lighthive/blob/master/lighthive/node_picker.py

It uses get_dynamic_global_properties call to measure response time. If hive-engine have the same api/format, then it should work directly, otherwise you need to customize it a little bit.

i wish hivedevs had a weekly discord party where they would celebrate hive developments and maybe use that @tipcc free tip.cc bot to give out hive hbd or hive engine tokens (which are easy to mint and give out )

i wanna see hive devs attractive university students, interns and twitter and reddit freelance communities of open source coders and developers and students who want to learn about hive and start working on it as i believe hive is a dream job / career for millions of people maybe billions

Hey can Hive even support 5 to 10 billion accounts in its current incarnation? What upgrades have to be made to witness nodes or resource credits before we can scale up to 100s of millions or billions of accounts or would they all be severely limited and all have to be given rotated delegation to ever like or comment or post?

Keep up the great work 👏🏾

Eline sağlık abi. Öğrenilecekler listeme yeni bir tane daha. Hadi Python'layalım. 😎🧑‍💻 🧑‍🚀👨‍💻

What is this?

Thank you very useful information. I hope you can always develop good applications, always healthy for you, have a nice day.

I feel like I don't have a clue what this post even is about! But hey, thank you for whatever it is! (Insert I am not a programmer joke here....)

This is great work thanks @emrebeyler for the informative post.

The partner who really cleaned up the very basic code I wrote up for @podping has been forever horrified by the Beem library I used.

For some reason I wasn't aware of this but I'm very pleased to have suddenly noticed it.

I wonder if anyone here want's to look at Podping's Hive related code and see if it would be easy to switch out Beem specifically because Podping is Async and Beem isn't.

The two most active parts of the code in terms of Hive are here:

https://github.com/Podcastindex-org/podping-hivewriter/blob/main/src/podping_hivewriter/hive.py

and here:

https://github.com/Podcastindex-org/podping-hivewriter/blob/main/src/podping_hivewriter/hive_wrapper.py

I will start doing this myself in the next couple of days but if anyone here wants to look or thinks its easy, please get in touch with me.

Any plans on extending the async code for lighthive towards the client API?

Yes, I have some plans to support non-blocking calls.

Would be really cool if in the future it could become possible if something like this could be possible with lighthive. For me knowing it likely will helps me to finally retire the idea of restarting a project like asyncsteem for Python3/Hive/asyncio from the bottom of my current priorities list ;-)

Congratulations @emrebeyler! Your post has been a top performer on the Hive blockchain and you have been rewarded with the following badge:

Post with the highest payout of the week.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Happy New Year - Feedback from the first Hive Power Up Day of 2022
PUD - PUH - PUM - It's all about to Power Up!

OK trying this out... Question though, if I'm already in async code can I pass an existing loop through to it?

Exception has occurred: RuntimeError
This event loop is already running
  File "/Users/gbishko/Documents/Python-iMac/hive-lightning/v4vapi/scanner2.py", line 14, in run
    client = Client(loglevel=logging.DEBUG, automatic_node_selection=True)
  File "/Users/gbishko/Documents/Python-iMac/hive-lightning/v4vapi/scanner2.py", line 22, in <module>
    asyncio.run(run())

you can use

import nest_asyncio
nest_asyncio.apply()

at the top of your script (after installing nest-asyncio) for a band-aid solution. Even though node selection is async, lighthive is not async-friendly. RPC calls are all sync, at the moment, and by design lighthive is not thread-safe/concurrency-safe.

I have plans to add support for async calls, but it's not there yet. So, I would suggest not using lighthive in async environments unless you know what you're doing.

If the automatic node selection is what you need, then this module is pretty much can be used in your project:

https://github.com/emre/lighthive/blob/master/lighthive/node_picker.py

import nest_asyncio
nest_asyncio.apply()

That's working nicely but I have a question: do you have any equivalent to Beem's no_broadcast setting which I find tremendously useful in unit-tests.

I'm looking hard at building parts of this into my application now. I think we will and certainly if you continue to develop toward full async I'll be a fan.

or wait a little bit, I've plans for a lighthive-asyncio package. :)

Thanks for this are you open to accepting contributions on the project