TATECHATLAS
◎ English
Home / Topics

Programming: Python, Git and code examples

Python and Git guides covering dependencies, environments, change history and code examples with explanations and primary sources.

Choose the problem you need to solve: a Python environment, package imports or Git history. Check commands against your tool version and the conditions of your project.

Materials

30 materials

PurePath versus Path: when path math is not filesystem truth

Use PurePath-family classes for portable, I/O-free path manipulation and Path/PosixPath/WindowsPath for filesystem-backed work. Do not treat lexical normalization as proof that a target exists, resolves through symlinks, or is contained.

pathlib / PurePath / Path / symlinks / resolve / filesystem checks

How json.loads and json.load handle bytes and bytearray in Python: encoding auto-detection and the strict parameter

The json.loads and json.load functions in Python accept bytes and bytearray inputs since version 3.6, automatically detecting UTF-8, UTF-16, or UTF-32 encoding. If the encoding is incorrect, UnicodeDecodeError is raised. The strict parameter controls handling of control characters in JSON strings. Practical scenarios and limitations are discussed.

Python 3.6+ / JSON / bytes and bytearray / UTF-8/UTF-16/UTF-32 / UnicodeDecodeError / strict parameter / pathlib / binary files

Combining Static and Dynamic Metadata in pyproject.toml

In pyproject.toml, static metadata keys are declared directly in the file, while dynamic keys are listed in the project.dynamic array so a build backend can supply their values at build time. A backend must honour statically specified keys that are not listed in dynamic, and it must raise an error if name appears in dynamic. When a key is specified both statically and in dynamic (PEP 808), the backend may only append entries and must not modify or remove existing ones.

pyproject.toml / PEP 621 / PEP 808 / build backend / dynamic metadata / versioning / setuptools_scm / reproducible builds

Mastering JSON Output Formatting in Python

Learn how to control JSON serialization using separators, indentation, key sorting, and ASCII encoding to optimize for machine or human readability.

python / json / serialization / formatting / api / debugging / encoding / data-interchange

Entry Points in pyproject.toml

Learn to declare entry points in pyproject.toml using the three supported tables. Avoid nested subtables and duplicate definitions to prevent installation errors.

Python / Packaging / pyproject.toml / Entry Points / CLI / Scripts

Separating Build Dependencies from Runtime Dependencies in pyproject.toml

To avoid version conflicts and ensure reproducible installs, use [build-system].requires for build tools only and [project].dependencies for runtime libraries. Pin exact versions in a separate requirements.txt generated with pip freeze or pip-compile.

pyproject.toml / dependencies / packaging / reproducibility / pip / pip-tools

Using pip freeze and --no-deps for Repeatable and Secure Python Package Installation

pip freeze captures all direct and transitive dependencies in a requirements file, ensuring repeatable installations. Using --no-deps during installation adds a safety layer by preventing automatic installation of transitive dependencies. For stronger integrity guarantees, hash-checking mode with pip-compile --generate-hashes verifies downloaded artifacts, although no strategy fully eliminates repository or supply-chain risks.

pip / dependencies / install / freeze / no-deps / repeatable / security / requirements

Declaring and resolving extras in pyproject.toml, including self-referential groups

Each key under [project.optional-dependencies] becomes a Provides-Extra entry whose dependency array elements are gated by an environment marker, so pip only installs them when the user requests the bracket syntax. Self-referencing extras compose groups but require modern package managers.

pyproject.toml / optional-dependencies / extras / self-referential-extras / PEP-621 / packaging

SHA-256 hashes versus wheelhouse for repeatable Python server deployments

Use SHA-256 hash-checking when servers can still reach an index but you need tamper resistance beyond version pinning; use a wheelhouse when the server is offline or must avoid recompilation. Choose the repeatability level by environment: pinning for a cross-platform baseline, hashes for automated tamper protection, and wheelhouse for full offline isolation with portability limits.

pip / repeatable installs / SHA-256 hash-checking / wheelhouse / requirements.txt / offline deployment / server deployment / Python packaging

Describe build and project metadata in pyproject.toml without breaking repeatable pip installs

Use [build-system] for build-time dependencies and [project] for runtime dependency specifiers, then keep pyproject.toml as a declaration rather than a lockfile. For repeatable installs, generate a separate pinned requirements file, add hash-checking, or build a wheelhouse bundle instead of overloading pyproject.toml with locked install state.

pyproject.toml / build-system / project metadata / repeatable installs / pip / pinning / hash-checking / wheelhouse

Robust CSV Parsing in Python: Handling BOM, Dialects, and Newlines

A guide to using the Python csv module to automatically detect delimiters, handle Unicode Byte Order Marks (BOM) with utf-8-sig, and manage platform-specific newline issues using the Sniffer class and correct file opening parameters.

python / csv / data-processing / encoding / utf-8-sig / automation

Serializing Complex Python Objects to JSON with Custom Encoders

Use default or a JSONEncoder subclass to convert unsupported Python values into an explicit JSON representation. An unhandled TypeError stops the whole dump. Add object_hook only when you need to reconstruct custom types from marker objects.

json / serialization / JSONEncoder / default / object_hook / python-standard-library / datetime / complex

Creating and using a wheelhouse for offline Python installs

A wheelhouse is a pre-built directory of wheels created on a network-connected build machine and installed offline on a target machine. Pin a requirements file, run pip wheel, archive with tar, then install with --no-index --no-deps --force-reinstall.

wheelhouse / offline-install / pip-wheel / repeatable-installs / hash-checking / requirements-file / pyproject-toml / build-dependencies