Browse Docs

Python

In this section

  • ๐ŸŒ… UV

    Install

    1# curl method
    2curl -LsSf https://astral.sh/uv/install.sh | sh
    3
    4# Pip method
    5pip install uv
    

    Quick example

    1pyenv install 3.12
    2pyenv local 3.12
    3python -m venv .venv
    4source .venv/bin/activate
    5pip install pandas
    6python
    7
    8# equivalent in uv
    9uv run --python 3.12 --with pandas python
    

    Usefull

    1uv python list --only-installed
    2uv python install 3.12
    3uv venv /path/to/environment --python 3.12
    4uv pip install django
    5uv pip compile requirements.in -o requirements.txt
    6
    7uv init myproject
    8uv sync
    9uv run manage.py runserver
    

    Run as script

    • Put before the import statements:
    1#!/usr/bin/env -S uv run --script
    2# /// script
    3# requires-python = ">=3.12"
    4# dependencies = [
    5# "ffmpeg-normalize",
    6# ]
    7# ///
    

    Then can be run with uv run sync-flickr-dates.py. uv will create a Python 3.12 venv for us. For me this is in ~/.cache/uv (which you can find via uv cache dir).

  • ๐Ÿ‘พ Pypi Repository

    Pypi Repo for airgap env

    Let’s take as an example py dependencies for Netbox

     1# Tools needed
     2dnf install -y python3.11
     3pip install --upgrade pip setuptool python-pypi-mirror twine
     4
     5# init mirror
     6python3.11 -m venv mirror
     7mkdir download
     8
     9# Get list of Py packages needed
    10curl raw.githubusercontent.com/netbox-community/netbox/v3.7.3/requirements.txt -o requirements.txt
    11echo pip >> requirements.txt
    12echo setuptools >> requirements.txt
    13echo uwsgi >> requirements.txt
    14
    15# Make sure repository CA is installed
    16curl http://pki.server/pki/cacerts/ISSUING_CA.pem -o /etc/pki/ca-trust/source/anchors/issuing.crt
    17curl http://pki.server/pki/cacerts/ROOT_CA.pem -o /etc/pki/ca-trust/source/anchors/root.crt
    18update-ca-trust
    19
    20
    21source mirror/bin/activate
    22pypi-mirror download -b -d download -r requirements.tx
    23twine upload  --repository-url https://nexus3.server/repository/internal-pypi/ download/*.whl --cert /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
    24twine upload  --repository-url https://nexus3.server/repository/internal-pypi/ /download/*.tar.gz --cert /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
    

    Then on target host inside /etc/pip.conf :

  • ๐Ÿ”— Dependencies

    Package with pip3

    1pip3 freeze netaddr > requirements.txt
    2pip3 download -r requirements.txt -d wheel
    3mv requirements.txt wheel
    4tar -zcf wheelhouse.tar.gz wheel
    5tar -zxf wheelhouse.tar.gz
    6pip3 install -r wheel/requirements.txt --no-index --find-links wheel
    

    Package with Poetry

     1curl -sSL https://install.python-poetry.org | python3 -
     2poetry new rp-poetry
     3poetry add ansible
     4poetry add poetry
     5poetry add netaddr
     6poetry add kubernetes
     7poetry add jsonpatch
     8poetry add `cat ~/.ansible/collections/ansible_collections/kubernetes/core/requirements.txt`   
     9
    10poetry build
    11
    12pip3 install dist/rp_poetry-0.1.0-py3-none-any.whl
    13
    14poetry export --without-hashes -f requirements.txt -o requirements.txt
    

    Push dans Nexus

    1poetry config repositories.test http://localhost
    2poetry publish -r test
    

    Images Builder

    1podman login registry.redhat.io
    2podman pull registry.redhat.io/ansible-automation-platform-22/ansible-python-base-rhel8:1.0.0-230
    3
    4pyenv local 3.9.13
    5python -m pip install poetry
    6poetry init
    7poetry add ansible-builder 
    
Thursday, January 15, 2026 Monday, January 1, 1