Part 1: Coding on Hive With Python - Setting Up

This is the first post in series about coding with Hive APIs and working with Hive blockchain data. While there is interest in using other languages, I've decided to start with Python. There are some great Python modules for Hive and Python is noob-friendly.

This first post will be the most boring. It's necessary to get these setup steps out of the way before we can do some fun stuff. Let's get to it.

What we need to Set Up

To succeed with Python you need 2 pieces of software:

  • A text editor
  • The python interpreter

Any text editor will do. To have a better experience use an editor with syntax highlighting such as Visual Studio Code. VSCode is free, open-source, cross-platform, and often recommended. Syntax highlighting improves the coding experience because it makes it easier to spot simple errors and saves a lot of time.

Installing the Python Interpreter

The python interpreter is the piece of software that interprets and executes the Python code. It can be run in interactive mode or given a file as input. Input files typically use the '.py' file extension. The code examples for blogs will use Python version 3, so I recommend installing version 3.

Installing Python on Linux

The easiest way to install Python on Linux is to invoke the native package manager. For RedHat/CentOS the command is yum install python3. For Ubuntu/Raspbian the command is apt-get install python3.

Installing Python on macOS

The easiest way to install Python on macOS is using Homebrew - "The Missing Package Manager for macOS". Get started with Homebrew using the instructions found here: https://brew.sh/

Once Homebrew is good to go, invoke it from Terminal to install python like so: brew install python3

Installing Python on Windows

The easiest way to install Python on Windows is using Chocolatey - "The Package Manager for Windows". Get started with Chocolatey using the instructions found here: https://chocolatey.org/install.

Once Chocolatey is good to go, invoke it from PowerShell or Cmd prompt like so: choco install python

Alternatively, you can download a Python installer from python.org, install it, and add Python to your PATH. Chocolatey does all of this for you.

Checking your Python install

Once you've completed installing Python version 3, a quick check confirms everything is in order.

From your Terminal, run the command python3 --version. On Windows Cmd prompt / PowerShell run the command python --version. If all goes well, the Python executable is found and it spits out something like Python 3.9.5. If your OS can't find Python make sure it's on your environment PATH.

Bonus: a Pythonic Poem

Now that you have Python installed, fire up the interpreter by typing python into your terminal. It will spit out some version info and help text and then greet you with >>>, indicating it's waiting for your code to interpret.

In the next post, we'll dive into modules. Modules are like add-ons that can do all sorts of things including fetching data from the Hive blockchain. Python loads a module when given the keyword import. For now, type import this and hit enter for a nice surprise.

"Flat is better than nested." - Tim Peters, the Zen of Python


p.s. Thanks for reading. Please let me know if anything is unclear or incorrect. This is intended to be a living document to be improved and maintained over time.

H2
H3
H4
3 columns
2 columns
1 column
27 Comments
Ecency