Skip to main content

Poly

A simple command for converting and processing data from your clipboard.

Installation

Via pip

Poly is available on PyPi under the name poly-cli. To install it, simply do

python3 -m pip install poly-cli

Via pipx

From Python 3.12 and on, especially on Mac, you are warned against/forbidden from installing Python packages in an "externally-managed" environment (AKA in user space).

PIP will recommend that you install things using pipx which should manage virtual environments for you.

To install Poly this way, the interface is the same, so simply do

pipx install poly-cli

From this point on, the Poly CLI can be accessed with the cli command poly. See "Usage" below

Environment Variable Config

There are environment variables you can set to control the behavior of Poly:

POLY_CFG_COLOR

Default: 1

Setting this value to 0 will result in no syntax highlighting for output containing JSON/YAML/TOML.

Usage

This script will expect you to have the text it will manipulate in your clipboard. When you run a command, it will do its job, and if it is successful, it will put the modified text back into your clipboard, as well as send it to stdout.

You can generally convert data with the following format:

poly <from_format> <to_format>[ options]

Any other generic command is simply

poly <command>[ options]

You can find some basic help from the --help option at any level:

poly --help
poly json --help
poly yaml --help
...etc

STDIN and Unix Pipes

If you would like to pipe input into poly you can use the -z/--use-stdin command. Any command in poly can use this and the input will be read from stdin instead of the clipboard, allowing full unix piping, e.e.g

echo "{ \"foo\": \"bar\" }" | poly -z json pretty

NOTE: Even when using -z/--use-stdin, the output will still be sent to the clipboard AND stdout.

Chat Copypasta

A slowly-expanding list of chat programs to copy/paste out of into a more sane a readable format (thanks, emoji reactions...)

The intention is for each command to support both the webapp and the desktop client for each of the chat programs (Yes, they copy differently. No, you shouldn't be surprised.)

Supported chat program(s):

  • Slack (NOTE: CURRENTLY BROKEN AFTER SLACK UPDATED MESSAGE FORMAT)

Future support:

  • Discord
  • MS Teams

Conversions

All of the following formats convert between each other:

  • JSON
  • YAML
  • TOML
  • JWT
  • URL Query String (see below for what this means)

NOTE: Some data types (like null in TOML) won't convert and might be dropped!

Additionally, you can convert between color formats:

  • Hex (e.g. #123, #123456, #1234, #12345678)
  • RGB (e.g. (10, 10, 10), (5,5,5))
  • RGBA (e.g. (10, 10, 10, 10), (5,5,5,5))

JWT Conversion

Converting to JWT requires two additional options:

  • -s, --secret: A secret string to encode/decode with
  • -a, --algorithm: An algorithm to encode/decode with

URL Query String Type Conversion

When converting from a query string you can use the -c, --convert flag to tell poly to attempt to convert all the values in the query string. They all start as strings, but it will attempt to do things like convert "true" to true for JSON/YAML, etc. This only works for the basic data types; it will not do anything smart like nested objects/lists.

Example:

assuming your clipboard contains a=1&b=true&c=a,b,c...

poly query-string json --convert

will result in

{
  "a": 1,
  "b": true,
  "c": "a,b,c"   // note that this is NOT ["a", "b", "c"]
}

?foo=bar,baz,bat will be converted as a string of {"foo": "bar,baz,bat"}, not as a list of {"foo": ["bar", "baz", "bat"]} If you want a list to be built, simply use the same query param multiple times.

More complex example (including list and complex object):

assuming your clipboard contains

http://foo.bar.com?a=1&b=true&c=a,b,c&b=false&d={"foo":"bar"}

(note that this contains a url! oooooo....)

running:

poly query-string json --convert --include-url

will result in:

{
  "url": "http://foo.bar.com",  // from --include-url
  "a": 1,
  "b": [true, false],  // multiple 'b' params were combined into a list
  "c": "a,b,c",   // note that this is NOT ["a", "b", "c"]
  "d": {"foo": "bar"}   // oooooo fancy
}

This is all done using the Python builtin ast.literal_eval() -- a completely safe function that will attempt simply to convert the string to a valid Python literal, but does not execute the string as code.

JSON formatting (json)

Manipulate JSON data from the clipboard

All commands start with poly json

  • pretty: pretty-prints the JSON in your clipboard and sends it back to the clipboard
  • one-line: outputs the JSON in your clipboard as a single line of text and sends it back to the clipboard

Base64 (b64)

Encode/Decode Base64 data

  • poly b64 from: Takes base64-encoded data from the clipboard, outputs the decoded data, and sends it back to the clipboard
  • poly b64 to: Takes data from the clipboard, outputs base64-encoded data, and sends it back to the clipboard

Hash Functions

Supports md5, sha1, sha256, and sha512

URL Query Param Encoding/Decoding

  • poly url encode
  • poly url decode

Encodes strings like

a=1&b=true&c=a,b,c&b=false&d={"foo": "bar", "baz": "bat"}

into

a=1&b=true&b=false&c=a%2Cb%2Cc&d=%7B%22foo%22%3A%20%22bar%22%2C%20%22baz%22%3A%20%22bat%22%7D

and decodes them back again.

Both encode/decode also support -q, --quote-plus which allows for encoding spaces as + instead of %20

String Manipulation

  • Line sorting (line-sort): This will attempt to sort the lines of a \n-separated string in your clipboard
  • Spongebob (sponge, spongebob): I WoNDeR What ThIS doEs
  • Smart Quotes (quotes): Replaces those stupid “/”/‘/’ with proper quotes "/'
  • [Un]Escape Text (escape/unescape): Add/remove \ in a string for given characters
  • Split Text (split): Split a string into multiple lines based on a given separator (default is ,)

Metadata

Release files for poly-cli 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poly-cli 1.2.1
File Size Uploaded Provenance Actions
poly_cli-1.2.1.tar.gz 23.8 kB Without provenance Details for poly_cli-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for poly-cli 1.2.1
File Interpreter ABI Platform Actions
poly_cli-1.2.1-py3-none-any.whl Python 3 none any Details for poly_cli-1.2.1-py3-none-any.whl

Total release size: 46.5 kB

Release files / poly_cli-1.2.1.tar.gz

Download URL poly_cli-1.2.1.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0012db3f033c896b0eddb46149900512a0467eb2577c0703bb3201a9507f1e8c
BLAKE2b-256 checksum
How to use checksums
87e411a1c5d6966f2f0b752dd9d0461b8a9c0ab5afa5589b3d7e294077bdd3e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.10

Release files / poly_cli-1.2.1-py3-none-any.whl

Download URL poly_cli-1.2.1-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37d4d937158fab7661b9e29cd7f9b5fef49075ab011d25f14f9ec2c005cb65d4
BLAKE2b-256 checksum
How to use checksums
8d754f494f081e37fc0fa3bd3cdc5e0bbe479ea3580635a663b523d7d0113c82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.10

Security for poly-cli 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page