Skip to main content

Terminal buddies to store and run python snippets

Project description

pypals: it really does nothing!
pypals
Turn python snippets into command line buddies!

Keeps your python scripts and snippets as command line pals.

PyPI version

Downloads

installation

Get the package from pypi i.e.

$ python3 -m pip install pypals --upgrade

see screen shot in archive folder for using pypal in vscode terminal

usage

Sometimes you write code maybe to do some random job or snippet, scrape something, send a tweet, whatever.

It's useful to keep those bits of odd code somewhere. pypals are easy to remember ages later.

$ python3 -m pypals sportsfan
$ sportsfan doesn't exist, create them now? yes or no
$ > yes
$ your name?
$ > mike
$ Hi my name is sportsfan, Thankyou for creating me!
$ I am listening...

sportsfan has been created for you in a /pypals directory. He can gather data about sports using any python commands you write and put in that folder

now try running this command...

$ hello

now look in pypals/sportsfan/hello/hello.py file to see an example of a command.

To create commands try typing 'do something' at the prompt.

You will see it creates it for you. You can now just edit the file created and fill it in with your code.

Next try typing 'quit'

If you're editing a command you don't need to restart pypal. It will reload the command. You can even type 'r' to rerun it at the prompt.

parameters

pass any words after your command it will pick them up as parameters.

when creating a command it will ask you what to type as a response, you can put any string. however if you try instead typing:

{args}

Now run your command and type some extra words after it. cool huh.

  • TODO - explain commands between bots / sharing commands you can import pypals into other pypals and share commands between them.

logging

  • todo - explain logging. now off by default.

You can also call or execute any commands you created directly from the command line. i.e.

python3 -m pypals sportsfan hello

meta / vars

At the root of every pypal you create is a _meta file to store variables.

If you don't like json you can change the config type (see below)

You can access any variables stored in _meta from your commands by using the passed in 'o' which is a reference to self.

print(f"Hello, to you { o.o['friend']}!")

You can store more variables in there if required just add them manually.

shortcuts

While a given pypal is running you can pass it the following single letter commands as shortcuts:

r - re-run previous command. (i.e. after editing the python file)

h - history

q - quit

c - list all the variables in the config file

c=json - change the config file to be json

c=ini - change the config file to be ini

c=xml - change the config file to be xml

c=txt - change the config file to be txt

d - generate a docs file inside the given pypals folder that list out all the commands you have created. (once you create a docs file for a pypal, it will auto update every time you create a new command. so don't edit it manually or you will lose your changes.)

CLI

pypals has recently been updated to have a cli help system.

the following command might be useful...

for a list of all commands

$ python3 -m pypals -h

the version of pypals you are using

$ python3 -m pypals -v

show a list of all your pypals

$ python3 -m pypals -l 

generate a top level docs file that lists out all your pypals in the root of the pypals folder.

$ python3 -m pypals -d

API

Every command gets passed a reference to self 'o' which is a reference to the pypals object.

There are some commands you can use on this object. But mostly you can use pypal to create your own

TODO - explain API

documentation

  • note : you can't use package names for commands. i.e. builtins, test
  • note : use task manager to montior bots

the base path to a command is available if loading writing files to same folder:

o.context.COMMAND_PATH

pypals uses includes rich and domonic libraries so your commands should be able to import and use them.

more

cron notes

put in sometask.sh file chmod +x the file.

echo "do some job batch 1" | nohup python3 -m pypals jobs >/dev/null 2>&1 &
  • you may want those to self terminate *see 'quit'

makefile notes

something like this in your makefile to boot one or more faster

pypal:
	cd /home/ubuntu/Desktop/someapp/automate/; \
	python3 -m pypals myscraper somefunc

If you run several pypals simoultaneously you can trash them all easy by putting this in your makefile:

killall:
	pkill -9 python

Notes

https://medium.com/@joel.barmettler/how-to-upload-your-python-package-to-pypi-65edc5fe9c56

about

pypals was my first python project written in python2 in about 2012. It is a useful way to organise code snippets and do research. In 2019 I ported it to python 3 while learning to make pip packages.

please use it responsibly and if you want to contribute, fork it and send me a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypals-1.0.4.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

pypals-1.0.4-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file pypals-1.0.4.tar.gz.

File metadata

  • Download URL: pypals-1.0.4.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pypals-1.0.4.tar.gz
Algorithm Hash digest
SHA256 c011d214797febb873b80aca54cf64bd44c970e8bc4c3a1c6bf908b59511445a
MD5 08818044bfc3c35ee8e823241c156ecd
BLAKE2b-256 db644fbddbc549a9e8d582d337508ff2038df8e473339e996fa08243ea6fac62

See more details on using hashes here.

File details

Details for the file pypals-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: pypals-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pypals-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bb4418ba7851d5457e69397e7e1ea5b5659a4182d2aa86bedd081a2ebc0ca711
MD5 2770c257740e12f9087506eafa2f2d45
BLAKE2b-256 9c20fa6729a3e70d53a494744ad63f79d57f18dc355ab60a8fd7071b7bafe9ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page