* http.server
To run a localhost webserver on port 8000, serving the content of the current directory:
python -m http.server
This takes an optional port. To change port, do this:
python -m http.server 8001
Pass -h for more options.
*base64
python3.11 -m base64 -h
usage: .../base64.py [-h|-d|-e|-u|-t] [file|-]
-h: print this help message and exit
-d, -u: decode
-e: encode (default)
-t: encode and decode string 'Aladdin:open sesame'
* asyncio
This provides a Python console with top-level await:
python -m asyncio
asyncio REPL 3.11.4 (main, Jun 20 2023, 17:23:00) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> import httpx
>>> async with httpx.AsyncClient() as client:
... r = await client.get('
https://www.example.com/')
...
>>> r.text[:50]
'<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta ht'
* tokenize
This is fun - it's a debug mode for the Python tokenizer. You can run it directly against a file:
python -m ast cgi.py | head -n 10
Module(
body=[
Expr(
value=Constant(value='Support module for CGI (Common Gateway Interface) scripts.\n\nThis module defines a number of utilities for use by CGI scripts\nwritten in Python.\n\nThe global variable maxlen can be set to an integer indicating the maximum size\nof a POST request. POST requests larger than this size will result in a\nValueError being raised during parsing. The default value of this variable is 0,\nmeaning the request size is unlimited.\n')),
Assign(
targets=[
Name(id='__version__', ctx=Store())],
value=Constant(value='2.6')),
ImportFrom(
module='io',
* json.tool
Pretty-print JSON:
echo '{"foo": "bar", "baz": [1, 2, 3]}' | python -m json.tool
{
"foo": "bar",
"baz": [
1,
2,
3
]
}
Tip from Joe Kerhin:
json.tool will also exit with nonzero status if your json document is invalid.
* random
I thought this might provide a utility for generating random numbers, but sadly it's just a benchmarking suite with no additional command-line options:
python -m random
0.000 sec, 2000 times random
avg 0.49105, stddev 0.290864, min 0.00216092, max 0.999473
* calendar
Show a calendar for the current year:
python -m calendar
January
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
This one has a bunch more options (visible with -h). python -m calendar -t html produces the calendar in HTML, for example.
https://til.simonwillison.net/python/stdlib-cli-tools
--
FROM 59.60.25.*