home blog portfolio Ian Fisher

Useful Python libraries

See also: wiki/python and ref/python

prompt_toolkit – REPLs

https://python-prompt-toolkit.readthedocs.io/en/master/index.html

from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory

history = FileHistory("~/.myhistory")
session = PromptSession(
    "> ", multiline=True, prompt_continuation=". ", history=history
)

while True:
    message = session.prompt()
    # ...

requests – HTTP requests

https://requests.readthedocs.io/en/latest/

import requests

response = requests.get(url, headers={"X-My-Header": "..."})
data = response.json()

requests.post(url, json=my_json_payload)