devops101 › Cheat sheet'ler › 🐍 Python (DevOps) cheat sheet

🐍 Python (DevOps) cheat sheet

Ortam

python3 -m venv .venv && source .venv/bin/activateSanal ortam
pip install -r requirements.txtBağımlılık kur
pip freeze > requirements.txtSürümleri sabitle
python -m http.server 8000Hızlı dosya sunucusu
python -m json.tool dosya.jsonJSON biçimlendir

Kalıplar

import requests; r = requests.get(url, timeout=5); r.raise_for_status()HTTP isteği (timeout şart)
import os; os.environ["ANAHTAR"]Ortam değişkeni
import subprocess; subprocess.run(["ls","-l"], check=True)Komut çalıştır
import argparse; p=argparse.ArgumentParser(); p.add_argument("--x", type=int)CLI argümanı
import logging; logging.basicConfig(level=logging.INFO)Loglama
import json; json.loads(s); json.dumps(d, indent=2)JSON
import boto3; s3 = boto3.client("s3")AWS SDK

Test

pytest -qTestleri çalıştır
pytest -k isimİsimle seç
ruff check . && ruff format .Lint ve biçim

Uygulamada aç ve alıştırmaları çöz →