Christopher Flynn

Data Scientist
Data Engineer
PhD Mathematician

Open Source



Introducing Sleight-of-hand (soh)

2019-05-26 Feed

Sleight of hand, or soh is a new python package that I have been working on for the past few weeks. It is a CLI tool built with the python library click, which offers developers a simple way to do certain tedious and sometimes common operations associated with software and web development.

The package can be installed using pip like other packages, using pip install soh. Since this is a CLI tool, I also created a homebrew formula so that it may be installed system-wide. To install using homebrew, use the command brew install crflynn/formula/soh. This allows you to use soh even outside of a python project.

soh provides the user with a main set of commands and several command groups for expanded functionality on certain topics. On invoking soh from the command line, users will see this:

$ soh
Usage: soh [OPTIONS] COMMAND [ARGS]...

  Sleight of hand CLI commands.

  (+) indicates command group. Use the -c flag on most commands to copy
  output to clipboard

  -h, --help  Show this message and exit.

  b64      + Base64 operations
  create   + Create files
  dt       + Datetimes
  epoch    + Epoch times
  json     JSON printing
  jwt      Display JWT contents
  secret   + Secrets generators
  serve    Simple http server at current directory
  sys      + System information
  uuid     Generate UUIDs
  version  soh CLI version

Commands with a description starting with + symbol indicate that they expand into sub-commands. For instance, using the command soh sys gives a more detailed set of subcommands for system information.

$ soh sys
Usage: soh sys [OPTIONS] COMMAND [ARGS]...

  System information.

  -h, --help  Show this message and exit.

  all       System information
  arch      OS architecture
  cores     Number of cores
  eip       External IP address
  ip        Local IP address
  mac       Local MAC address
  machine   Machine information
  node      Machine name
  platform  Platform type
  proc      Processor information
  version   OS version

At any command, a user may pass -h or --help for more detailed help. In addition, the -c flag can be passed for every command in order to copy the output to your clipboard. You will get a small notification at the end of the output that looks like this:

$ soh uuid -c
b712d560-ec1c-401d-a063-eeff7af84441 (copied to clipboard 📋)

Some of the most useful commands, in my opinion, are the following:

# Generate a uuid (v4)
$ soh uuid

# Get your external IP address
$ soh sys eip

# Get epoch seconds from a timestamp
$ soh epoch from '2009-02-25T03:40:34+00:00'

# Get a timestamp from epoch seconds
$ soh dt from 1560054000

# b64 encode a string
$ soh b64 e my_secret_message

# b64 decode a message
$ soh b64 d bXlfc2VjcmV0X21lc3NhZ2U=

# Display a JWT's contents
$ soh jwt eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
header = {
    "alg": "HS256",
    "typ": "JWT"
payload = {
    "sub": "1234567890",
    "name": "John Doe",
    "iat": 1516239022
signature = "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"

# Generate a secret password
$ soh secret pw

Hopefully this tool helps out with your development needs. Feel free to provide feedback on GitHub!

Further reading



Python Package Index

Back to the posts.