python

pip3 list -o --user --format=json | jq '.[]["name"]' | xargs pip3 install -U --user
py-ver.py
#!/usr/bin/env python3

import sys

print(sys.version)
#print(sys.version_info)
import gzip
from pathlib import Path

for f in Path('nt.gz').glob('*.gz'):
    with gzip.open(f, mode='rt') as fo:
        for x in filter(None, fo.readlines()):
            if x.strip():
                print(f, x, sep='\n\t')
                break
import lzma
from pathlib import Path

for f in Path('nt.xz').glob('*.xz'):
    with lzma.open(f, mode='rt') as fo:
        for x in filter(None, fo.readlines()):
            if x.strip():
                print(f, x, sep='\n\t')
                break

Build python from source

./configure --enable-optimizations --with-lto --enable-loadable-sqlite-extensions
make -j8
make altinstall

Debug

import pdb; pdb.set_trace()

Pretty counter

def PC(z, flt=None):
    for x, n in C(z).items():
        print(f'{n:6}  {x}')

median stdlib-only

def median(z):
    # ---- checks/conversions
    # try:
    #     z = sorted(map(int, map(str.strip, z.split(',')))
    #                if isinstance(z, str)
    #                else z)
    # except Exception as e:
    #     return None
    # ---- checks/conversions
    n = len(z)
    i = n // 2
    return z[i] if n % 2 else sum(z[i-1:i+1]) / 2

fastapi, sqlalchemy, sqlmodel modules location

fastapi
    Depends
    FastAPI
    Header
    HTTPException
    Request
    File
    UploadFile

fastapi.middleware.cors
    CORSMiddleware


sqlalchemy
    func
    or_

sqlalchemy.orm
    Session

sqlalchemy.sql.expression
    union_all


starlette.responses
    RedirectResponse


sqlmodel
    create_engine
    
    Field
    Relationship
    SQLModel

python wheels to offline

  1. prepare

    pip3 wheel --wheel-dir=./wheelz -r requirements.txt
    # or
    pip3 download --prefer-binary --dest _tmp/whl Jinja2 Jinja2 docker
  2. offline Dockerfile

    COPY wheelz __copied_wheels__
    RUN pip3 install --no-cache-dir --no-index --find-links=__copied_wheels__ \
        -r requirements.txt \
        # or
        1.whl 2.whl ... \
    && rm -rf __copied_wheels__