Created
December 23, 2025 19:55
-
-
Save bsweger/57c20051689f347f0c1cc4f9ee21ed11 to your computer and use it in GitHub Desktop.
Python REPL startup file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import contextlib | |
| import csv | |
| import datetime as dt | |
| import json | |
| import os | |
| import pprint | |
| import subprocess | |
| import sys | |
| import tempfile | |
| from dataclasses import dataclass | |
| from datetime import datetime, date, timedelta | |
| from io import open | |
| from pathlib import Path | |
| from pprint import pp | |
| VENV = os.environ.get("VIRTUAL_ENV") | |
| try: | |
| import tomllib | |
| except ImportError: | |
| # if we're in a python version < 3.11 | |
| pass | |
| # make the repl more colorful is rich is available | |
| try: | |
| import rich | |
| from rich import pretty | |
| from rich import print | |
| pretty.install() | |
| except ImportError: | |
| pass | |
| try: | |
| import polars as pl | |
| # format numeric format in polars DataFrame | |
| pl.Config.set_thousands_separator(True) | |
| # display full width of polars DataFrame | |
| pl.Config.set_tbl_width_chars(-1) | |
| # display all rows of a polars Series or DataFrame | |
| pl.Config.set_tbl_rows(-1) | |
| except ImportError: | |
| pass | |
| class FormattedOutput: | |
| def __init__(self, command): | |
| self.command = command | |
| def __repr__(self): | |
| output = subprocess.run(self.command, capture_output=True, text=True).stdout | |
| return output | |
| # add few command line-esque variables for poking around without leaving the REPL | |
| gitll = FormattedOutput(["git", "log", "--oneline", "-n", "5"]) | |
| gitst = FormattedOutput(["git", "status"]) | |
| ls = FormattedOutput(["ls", "-la"]) | |
| printenv = FormattedOutput(["printenv"]) | |
| pwd = FormattedOutput(["pwd"]) | |
| uvpiplist = FormattedOutput(["uv", "pip", "list"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment