analitics

Pages

Showing posts with label python packages. Show all posts
Showing posts with label python packages. Show all posts

Sunday, January 11, 2026

Python Qt6 : test from PNG to SVG with potrace ...

Tests from two days ago with conversion from PNG format to SVG format with the python potrace package ...

Saturday, January 10, 2026

Python313 : testing the potracer python package.

Pure Python Port of Potrace. This is a python port of Peter Selinger's Potrace (based on 1.16 code).
Today, I install the python package with pip tool:
pip install potracer[cli]
Collecting potracer[cli]
...
Successfully installed potrace-cli-0.0.4 potracer-0.0.4
The dir command show me all of these :
dir(potrace)
['BezierSegment', 'Bitmap', 'COS179', 'CornerSegment', 'Curve', 'INFTY', 'Optional', 'POTRACE_CORNER', 
'POTRACE_CURVETO', 'POTRACE_TURNPOLICY_BLACK', 'POTRACE_TURNPOLICY_LEFT', 'POTRACE_TURNPOLICY_MAJORITY',
'POTRACE_TURNPOLICY_MINORITY', 'POTRACE_TURNPOLICY_RANDOM', 'POTRACE_TURNPOLICY_RIGHT', 'POTRACE_TURNPOLICY_WHITE',
'Path', 'Tuple', 'Union', '_Curve', '_Path', '_Point', '_Segment', '_Sums', '__builtins__', '__cached__', '__doc__',
'__file__', '__loader__', '__name__', '__package__', '__spec__', '_adjust_vertices', '_bestpolygon', '_calc_lon',
'_calc_sums', '_opticurve', '_smooth', 'bezier', 'bm_to_pathlist', 'cprod', 'cyclic', 'ddenom', 'ddist', 'detrand',
'detrand_t', 'dorth_infty', 'dpara', 'findnext', 'findpath', 'floordiv', 'interval', 'iprod', 'iprod1', 'majority',
'math', 'mod', 'np', 'opti_penalty', 'opti_t', 'pathlist_to_tree', 'penalty3', 'pointslope', 'process_path', 'quadform',
'reverse', 'setbbox_path', 'sign', 'sq', 'tangent', 'xor_path', 'xor_to_ref', 'xprod']
See GitHub project from the tatarize.
I used the default example from the github project and works very well.

Python Qt6 : use default PyQt styles to PyQt6 applications.

Today, about PyQt Styles to PyQt6 Applications.
This works with default themes and how to change these, and using different types of custom styling.
First , let's see the source code with default themes:
from PyQt6.QtWidgets import QStyleFactory
print(QStyleFactory.keys())
['windows11', 'windowsvista', 'Windows', 'Fusion']
Let's see the source code for this simple script with this theme windows11:
import sys
from PyQt6.QtWidgets import (
    QApplication, QLabel, QLineEdit, QComboBox, QPushButton,
    QCheckBox, QSlider, QVBoxLayout, QWidget
)
from PyQt6.QtCore import Qt

app = QApplication(sys.argv)
app.setStyle('windows11')

window = QWidget()
layout = QVBoxLayout(window)

# 1. QLabel
layout.addWidget(QLabel("Acesta este un QLabel"))

# 2. QLineEdit
layout.addWidget(QLineEdit("Text editabil"))

# 3. QComboBox
combo = QComboBox()
combo.addItems(["Optiunea 1", "Optiunea 2", "Optiunea 3"])
layout.addWidget(combo)

# 4. QCheckBox
layout.addWidget(QCheckBox("Bifează această opțiune"))

# 5. QSlider
slider = QSlider(Qt.Orientation.Horizontal)
layout.addWidget(slider)

# 5. QPushButton
button = QPushButton('Simple button !')
layout.addWidget(button)

# show the main windows 
window.show()
sys.exit(app.exec())

News : PyQt v6.10.2 Released .

PyQt v6.10.2 has been released. This is a bug-fix release.
  • Fixed a regression introduced in v6.5.0 in the handling of the return value of QSqlQueryModel.query().
  • Fixed a regression introduced in v6.10.1 in the handling of the return value of createMimeDataFromSelection() in QTextEdit and QPlainTextEdit.

Thursday, January 8, 2026

Python Qt6 : Check certificate of url.

Today, I will show this python script to check the certificate of url.
import sys
import ssl
import socket
from datetime import datetime

from cryptography import x509
from cryptography.hazmat.backends import default_backend

from PyQt6.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QLabel,
    QLineEdit, QPushButton, QTextEdit
)

def fetch_certificate_raw(hostname):
    """
    Connects to the server and retrieves the certificate in DER format.
    Also returns a validation status message.
    """

    # Create a default SSL context (validates certificates)
    context = ssl.create_default_context()

    try:
        # First attempt: strict validation
        with socket.create_connection((hostname, 443), timeout=5) as sock:
            with context.wrap_socket(sock, server_hostname=hostname) as ssock:
                der_cert = ssock.getpeercert(binary_form=True)
                return der_cert, "Certificate is VALID"

    except ssl.SSLError as e:
        # Certificate is invalid → try to retrieve it anyway
        try:
            unverified_context = ssl._create_unverified_context()
            with socket.create_connection((hostname, 443), timeout=5) as sock:
                with unverified_context.wrap_socket(sock, server_hostname=hostname) as ssock:
                    der_cert = ssock.getpeercert(binary_form=True)
                    return der_cert, f"Certificate is INVALID: {str(e)}"
        except Exception:
            return None, f"Could not retrieve certificate: {str(e)}"

    except Exception as e:
        return None, f"Connection error: {str(e)}"

def parse_certificate(der_cert):
    """
    Converts a DER-encoded certificate into a cryptography.x509 object.
    """
    return x509.load_der_x509_certificate(der_cert, default_backend())

class CertViewer(QWidget):
    """
    Main GUI window for the HTTPS certificate viewer.
    """
    def __init__(self):
        super().__init__()

        self.setWindowTitle("HTTPS Certificate Checker")
        self.setGeometry(200, 200, 700, 600)

        layout = QVBoxLayout()

        # Input label + text field
        layout.addWidget(QLabel("Enter URL (example: example.com):"))
        self.input = QLineEdit()
        layout.addWidget(self.input)

        # Button to trigger certificate check
        self.button = QPushButton("Check Certificate")
        self.button.clicked.connect(self.check_certificate)
        layout.addWidget(self.button)

        # Output text box
        self.output = QTextEdit()
        self.output.setReadOnly(True)
        layout.addWidget(self.output)

        self.setLayout(layout)

    def check_certificate(self):
        """
        Triggered when the user presses the button.
        Retrieves and displays certificate information.
        """

        hostname = self.input.text().strip()

        # Clean URL (remove http://, https://, and paths)
        for prefix in ("https://", "http://"):
            if hostname.startswith(prefix):
                hostname = hostname[len(prefix):]

        hostname = hostname.split("/")[0]

        # Fetch certificate
        der_cert, status = fetch_certificate_raw(hostname)

        if der_cert is None:
            self.output.setText(status)
            return

        # Parse certificate
        cert = parse_certificate(der_cert)

        # Build output text
        text = f"=== CERTIFICATE STATUS ===\n{status}\n\n"
        text += "=== CERTIFICATE DETAILS ===\n\n"

        text += f"Subject:\n{cert.subject}\n\n"
        text += f"Issuer:\n{cert.issuer}\n\n"
        text += f"Serial Number: {cert.serial_number}\n\n"
        text += f"Version: {cert.version}\n\n"
        text += f"Valid From: {cert.not_valid_before}\n"
        text += f"Valid To:   {cert.not_valid_after}\n\n"

        # Check expiration
        if cert.not_valid_after < datetime.utcnow():
            text += f"⚠ Certificate EXPIRED on: {cert.not_valid_after}\n\n"

        # Subject Alternative Names (SAN)
        try:
            san = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName)
            text += f"Subject Alternative Names:\n{san.value}\n\n"
        except Exception:
            text += "Subject Alternative Names: (none)\n\n"

        self.output.setText(text)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    viewer = CertViewer()
    viewer.show()
    sys.exit(app.exec())

Tuesday, January 6, 2026

Python 3.13.0 : PyWin32 is full compatible with Python 3.13 .

Today I tried to use these python packages:
import win32serviceutil
import win32service
import win32event
import servicemanager
The works , but python -m pywin32_postinstall -install comes with:
python.exe: No module named pywin32_postinstall
NOTE : The copilot artificial intelligence, search and give me an old answer , but is wrong ...
PyWin32 is updated slowly, and at this moment there are no wheels for Python 3.13.
The pip tool cannot install pywin32 does not install anything usable, and pywin32_postinstall does not exist
Possible solutions
PyWin32 works perfectly on:
  • Python 3.12
  • Python 3.11
  • Python 3.10
If you need win32service, win32api, win32com, etc., you must use a supported version.
Need to see the last tutorial from my blogger.
I tested on admin with simple service and works:
python service_test_001.py install
Installing service MyPythonService
Service installed
This is the source code:
import win32serviceutil
import win32service
import win32event
import servicemanager
import time

class MyService(win32serviceutil.ServiceFramework):
    _svc_name_ = "MyPythonService"
    _svc_display_name_ = "My Python Windows Service"
    _svc_description_ = "A minimal Windows service example written in Python."

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.stop_event = win32event.CreateEvent(None, 0, 0, None)
        self.running = True

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.stop_event)
        self.running = False

    def SvcDoRun(self):
        servicemanager.LogInfoMsg("MyPythonService is starting.")
        self.main()

    def main(self):
        while self.running:
            # Your service logic goes here
            time.sleep(5)
            servicemanager.LogInfoMsg("MyPythonService heartbeat.")


if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(MyService)

Sunday, January 4, 2026

Python 3.13.0 : how to install pywin32_postinstall.

Today a tutorial on how to install pywin32_postinstall.
This package is essential for accessing Windows-specific functionalities in Python.
The pywin32_postinstall missing python error typically occurs when the pywin32 package is not properly installed or the post-installation script is not executed correctly.
Fisrt install the pywin32 python package.
pip install pywin32
The next step is to run this command on the path with Script folder.
python C:\Python313\Scripts\pywin32_postinstall.py -install
Parsed arguments are: Namespace(install=True, remove=False, wait=None, silent=False, quiet=False, destination= ...
The next step is to run this command on the path with Script folder.
D:\Python313_64bit>python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> print(win32api.GetVersion())

Friday, January 2, 2026

Python Qt6 : script for impact on your development workflow using scans features.

Impact on development workflows that rely on Language Server Protocol (LSP) features.
1. Editor Limitations
Your editor (VS Code, Neovim, Qt Creator, etc.) attempts to send a file to the Language Server, but the file is not accessible through the file:// protocol.
When this happens, the LSP rejects the request, and you lose essential features such as:
  • IntelliSense
  • Autocomplete
  • Hover information
  • Diagnostics
  • Jump‑to‑definition
  • Refactoring tools
2. Issues in Non‑Standard Projects
This limitation becomes more severe when working with:
  • dynamically generated files
  • files inside containers
  • remote workspaces
  • build systems that create temporary or virtual files
Since the LSP cannot process these resources, you lose intelligent code support.
3. Toolchain Breakdowns
If you rely on an automated workflow (analysis, diagnostics, UI integration, etc.), an LSP restricted to file:// can break:
  • static analysis
  • code validation
  • report generation
  • plugin integrations
Real Risks in Development
1. False or Incomplete Diagnostics
The LSP may not see the actual files, leading to:
  • false errors
  • missed real errors
2. Dangerous Refactoring
If the LSP cannot access all files, automated refactoring may:
  • fail to update all references
  • introduce new bugs
3. Reduced Productivity
Without full LSP support, you lose:
  • intelligent completion
  • fast navigation
  • real‑time validation
4. Incompatibility With Modern Tooling
Many modern IDEs rely on virtual or remote workspaces. An LSP limited to file:// becomes outdated quickly.
5. Indirect Security Risks
Not a vulnerability by itself, but:
  • if the LSP cannot analyze remote files, you may miss security issues in generated or synchronized code.
I tested with a simple python source code to detect how bad is running on I.D.E. The script continuously scans your Windows system to detect, analyze, and report the real‑time behavior, resource usage, crashes, leaks, ports, and child processes of all VS Code, LSP, and Antigravity components, showing their impact on your development workflow through a live PyQt6 dashboard.
The result after runnig is:

Thursday, January 1, 2026

Python Qt6 : QCalendarWidget simple example with csv file.

Here is a simple example of source code with PyQt6 and QCalendarWidget to create a calendar. You click on the date and enter a note. This is saved in a file with the date time ... and the note. When you reopen the script, it opens in notepad and the saved notes. Obviously it is a simple example but you can improve it with databases, make a note management, encrypt it, link it to an external database, etc.
import sys
import csv
import os
import subprocess
from datetime import datetime
from PyQt6.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QCalendarWidget,
    QInputDialog, QMessageBox
)
from PyQt6.QtCore import QDate


CSV_FILE = "note.csv"


class CalendarApp(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Calendar cu notițe")
        self.resize(400, 300)

        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.calendar = QCalendarWidget()
        self.calendar.clicked.connect(self.adauga_nota)
        self.layout.addWidget(self.calendar)

        # Dicționar pentru notițe
        self.note = {}

        # La pornire, citește CSV și deschide în Notepad
        self.incarca_note()

    def adauga_nota(self, date: QDate):
        zi = date.toString("yyyy-MM-dd")

        text, ok = QInputDialog.getText(self, "Adaugă notiță",
                                        f"Introdu text pentru {zi}:")
        if ok and text.strip():
            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
            self.note[timestamp] = text.strip()
            QMessageBox.information(self, "Salvat",
                                    "Notița a fost adăugată.")

    def incarca_note(self):
        if os.path.exists(CSV_FILE):
            try:
                with open(CSV_FILE, "r", newline="", encoding="utf-8") as f:
                    reader = csv.reader(f)
                    for row in reader:
                        if len(row) == 2:
                            self.note[row[0]] = row[1]

                # Deschide în Notepad
                subprocess.Popen(["notepad.exe", CSV_FILE])

            except Exception as e:
                QMessageBox.warning(self, "Eroare",
                                    f"Nu pot citi fișierul CSV:\n{e}")

    def closeEvent(self, event):
        try:
            with open(CSV_FILE, "w", newline="", encoding="utf-8") as f:
                writer = csv.writer(f)
                for timestamp, text in self.note.items():
                    writer.writerow([timestamp, text])
        except Exception as e:
            QMessageBox.warning(self, "Eroare",
                                f"Nu pot salva fișierul CSV:\n{e}")

        event.accept()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = CalendarApp()
    window.show()
    sys.exit(app.exec())
... this is the result:

Tuesday, December 30, 2025

Python Qt6 : video processing and background remover and sprites tool

It seems that the intrusion blocked my python and pip tool in command ... but I managed to create a tool with the python modules I had installed that would automatically remove my background and create sprites after a crop selection ... here's what it looks like with the character from the Easter project.
pyqt5 python video tool
... and result with crop and remove the green color from background:

Monday, December 15, 2025

Python Qt6 : ... tool for testing fonts.

Today I created a small Python script with PyQt6 using artificial intelligence. It is a tool that takes a folder of fonts, allows to select their size, displays the font size in pixels for Label text from the Godot engine and downloads only the selection of fonts that I like. I have not tested it to see the calculations with Godot, but it seems functional...

Saturday, December 13, 2025

Python Qt6 : ... search custom data in files with python and PyQt6.

The other day I noticed that I can't find what I worked on in the past, some files were blocked... Another task was blocking the artificial intelligence due to the number of uses. I could have used artificial intelligence to open old projects and ask where what I worked on is, but it would be a risk to waste my queries. Since I always use a specific signature when working on separate projects and the backup is distributed on storage that is always filling up, I created a simple script that would search for my custom with custom files, custom content and output a spreader with them. Here is the result of a 310-line source code script, obviously created with artificial intelligence.

Wednesday, December 10, 2025

Python 3.13.0 : ... simple script for copilot history.

NOTES: I have been using artificial intelligence since it appeared, it is obviously faster and more accurate, I recommend using testing on larger projects.
This python script will take the database and use to get copilot history and save to file copilot_conversations.txt :
import os
import sqlite3
import datetime
import requests
from bs4 import BeautifulSoup
import shutil

# Locația tipică pentru istoricul Edge (Windows)
edge_history_path = os.path.expanduser(
    r"~\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default\\History"
)

# Copiem fișierul History în folderul curent
def copy_history_file(src_path, dst_name="edge_history_copy.db"):
    if not os.path.exists(src_path):
        print("Nu am găsit istoricul Edge.")
        return None
    dst_path = os.path.join(os.getcwd(), dst_name)
    try:
        shutil.copy(src_path, dst_path)
        print(f"Am copiat baza de date în {dst_path}")
        return dst_path
    except Exception as e:
        print(f"Eroare la copiere: {e}")
        return None

def extract_copilot_links(db_path):
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()

    cursor.execute("""
        SELECT url, title, last_visit_time
        FROM urls
        WHERE url LIKE '%copilot%'
    """)

    results = []
    for url, title, last_visit_time in cursor.fetchall():
        ts = datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=last_visit_time)
        results.append({
            "url": url,
            "title": title,
            "last_visit": ts.strftime("%Y-%m-%d %H:%M:%S")
        })

    conn.close()
    return results

def fetch_conversation(url):
    try:
        resp = requests.get(url)
        if resp.status_code == 200:
            soup = BeautifulSoup(resp.text, "html.parser")
            texts = soup.get_text(separator="\n", strip=True)
            return texts
        else:
            return f"Eroare acces {url}: {resp.status_code}"
    except Exception as e:
        return f"Eroare acces {url}: {e}"

if __name__ == "__main__":
    copy_path = copy_history_file(edge_history_path)
    if copy_path:
        chats = extract_copilot_links(copy_path)
        if chats:
            with open("copilot_conversations.txt", "w", encoding="utf-8") as f:
                for chat in chats:
                    content = fetch_conversation(chat["url"])
                    f.write(f"=== Conversație: {chat['title']} ({chat['last_visit']}) ===\n")
                    f.write(content)
                    f.write("\n\n")
            print("Am salvat conversațiile în copilot_conversations.txt")
        else:
            print("Nu am găsit conversații Copilot în istoricul Edge.")

Saturday, December 6, 2025

News : Python 3.14.1 and Python 3.13.10 are now available!

... these are good news from 2 december 2025:
Python 3.14.1 is the first maintenance release of 3.14, containing around 558 bugfixes, build improvements and documentation changes since 3.14.0.
Python 3.13.10 is the tenth maintenance release of 3.13, containing around 300 bugfixes, build improvements and documentation changes since 3.13.9.
Read more on the official blogger.

Friday, December 5, 2025

Python Qt6 : ... data generator tool for a custom format file.

Today I finished a data generator tool for a custom format for a game. The idea is that PyQt6 is versatile and very useful for a developer. This tool generates data in the 2D area of a screen and saves them in a defined format, in this case a position and a size for a text ...
Here is the class for custom range selection sliders.
class RangeSlider(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self._min, self._max = 0, 1000
        self._start, self._end = 0, 1000
        self._dragging = None
        self.setMinimumHeight(24)

    def setRange(self, minimum, maximum):
        self._min, self._max = minimum, maximum
        self._start, self._end = minimum, maximum
        self.update()

    def setStart(self, val):
        self._start = max(self._min, min(val, self._end))
        self.update()

    def setEnd(self, val):
        self._end = min(self._max, max(val, self._start))
        self.update()

    def start(self): return self._start
    def end(self): return self._end

    def _pos_to_val(self, x):
        w = self.width()
        ratio = max(0, min(x, w)) / w if w else 0
        return int(self._min + ratio*(self._max-self._min))

    def _val_to_pos(self, val):
        w = self.width()
        return int((val-self._min)/(self._max-self._min)*w) if self._max>self._min else 0

    def mousePressEvent(self, e):
        x = e.position().x()
        sx, ex = self._val_to_pos(self._start), self._val_to_pos(self._end)
        self._dragging = "start" if abs(x-sx)<abs(x-ex) else "end"
        self.mouseMoveEvent(e)

    def mouseMoveEvent(self, e):
        if self._dragging:
            val = self._pos_to_val(int(e.position().x()))
            if self._dragging=="start": self.setStart(val)
            else: self.setEnd(val)

    def mouseReleaseEvent(self,e): self._dragging=None

    def paintEvent(self,e):
        p=QPainter(self); rect=self.rect()
        sx,ex=self._val_to_pos(self._start),self._val_to_pos(self._end)
        p.fillRect(rect,QColor(220,220,220))
        p.fillRect(QRect(QPoint(sx,0),QPoint(ex,rect.height())),QColor(100,200,100,120))
        p.setBrush(QColor(50,120,200)); p.setPen(Qt.PenStyle.NoPen)
        p.drawEllipse(QPoint(sx,rect.center().y()),6,6)
        p.drawEllipse(QPoint(ex,rect.center().y()),6,6)

Wednesday, December 3, 2025

Python 3.13.0 : ... playwright - part 001.

Playwright for Python is a modern automation library that allows developers to control browsers like Chromium, Firefox, and WebKit. It is widely used for testing, scraping, and simulating real user interactions.
The package provides an asynchronous API, enabling fast and reliable automation. Developers can launch browsers, navigate to pages, fill forms, click buttons, and capture results with minimal code.
In practice, Playwright is useful for tasks such as automated testing, repetitive searches, data collection, and simulating human-like browsing behavior across multiple browsers.
The example script demonstrates how to open Firefox, navigate to Google, perform a series of searches, scroll the page, and pause between actions to mimic natural user activity.
Additionally, the script saves each search query into a text file, creating a simple log of performed searches. This shows how Playwright can combine browser automation with file handling for practical workflows.
I used the pip tool then I install the playwright:
pip install playwright
playwright install
Let's see the script:
import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.firefox.launch(headless=False)
        context = await browser.new_context()
        page = await context.new_page()

        await page.goto("https://www.google.com")

        queries = [
            "python automation",
            "playwright tutorial",
            "google search automation"
        ]

        with open("results.txt", "w", encoding="utf-8") as f:
            for q in queries:
                # Fill search box
                await page.fill("textarea[name='q']", q)
                await page.press("textarea[name='q']", "Enter")
                await page.wait_for_load_state("domcontentloaded")

                # Scroll + pause
                await page.evaluate("window.scrollBy(0, document.body.scrollHeight)")
                await page.wait_for_timeout(3000)

                # Extract search results (titles + links)
                results = await page.query_selector_all("h3")
                f.write(f"\nResults for: {q}\n")
                for r in results[:5]:  # primele 5 rezultate
                    title = await r.inner_text()
                    link_el = await r.evaluate_handle("node => node.parentElement")
                    link = await link_el.get_attribute("href")
                    f.write(f"- {title} ({link})\n")

                print(f"Saved results for: {q}")

        await browser.close()

asyncio.run(main())
Then I run with this command:
python google_search_test_001.py
Saved results for: python automation
Saved results for: playwright tutorial
Saved results for: google search automation
Need to click to accept on browser ... , and some basic result on results.txt file:

Results for: python automation

Results for: playwright tutorial
- Playwright: Fast and reliable end-to-end testing for modern ... 

Sunday, November 30, 2025

News : the xonsh shell language and command prompt.

Xonsh is a modern, full-featured and cross-platform python shell. The language is a superset of Python 3.6+ with additional shell primitives that you are used to from Bash and IPython. It works on all major systems including Linux, OSX, and Windows. Xonsh is meant for the daily use of experts and novices.
The install is easy with pip tool:
python -m pip install 'xonsh[full]'

Python 3.13.0 : mitmproxy - part 001.

Mitmproxy is an interactive, open‑source proxy tool that lets you intercept, inspect, and modify HTTP and HTTPS traffic in real time. It acts as a "man‑in‑the‑middle" between your computer and the internet, making it possible to debug, test, or analyze how applications communicate online.
Why Python?
  • Mitmproxy is built in Python and exposes a powerful addon API
  • You can write custom scripts to automate tasks and traffic manipulation
  • Block or rewrite requests and responses with flexible logic
  • Inject headers or simulate server responses for testing
  • Integrate with other Python tools for advanced automation
  • Intercept and inspect HTTP and HTTPS traffic in real time
  • Modify requests and responses dynamically with Python scripts
  • Block specific hosts or URLs to prevent unwanted connections
  • Inject custom headers into outgoing requests for debugging or control
  • Rewrite response bodies (HTML, JSON, text) using regex or custom logic
  • Log and save traffic flows for later analysis and replay
  • Simulate server responses to test client behavior offline
  • Automate testing of web applications and APIs with scripted rules
  • Monitor performance metrics such as latency and payload size
  • Integrate with other Python tools for advanced automation and analysis
  • Use a trusted root certificate to decrypt and modify HTTPS traffic securely
Let's install:
pip install mitmproxy
Let's see the python script:
# addon.py
from mitmproxy import http
from mitmproxy import ctx
import re

BLOCKED_HOSTS = {
    "hyte.com",
    "ads.example.org",
}

REWRITE_RULES = [
    # Each rule: (pattern, replacement, content_type_substring)
    (re.compile(rb"Hello World"), b"Salut lume", "text/html"),
    (re.compile(rb"tracking", re.IGNORECASE), b"observare", "text"),
]

ADD_HEADERS = {
    "X-Debug-Proxy": "mitm",
    "X-George-Tool": "true",
}

class GeorgeProxy:
    def __init__(self):
        self.rewrite_count = 0

    def load(self, loader):
        ctx.log.info("GeorgeProxy addon loaded.")

    def request(self, flow: http.HTTPFlow):
        # Block specific hosts early
        host = flow.request.host
        if host in BLOCKED_HOSTS:
            flow.response = http.Response.make(
                403,
                b"Blocked by GeorgeProxy",
                {"Content-Type": "text/plain"}
            )
            ctx.log.warn(f"Blocked request to {host}")
            return

        # Add custom headers to outgoing requests
        for k, v in ADD_HEADERS.items():
            flow.request.headers[k] = v

        ctx.log.info(f"REQ {flow.request.method} {flow.request.url}")

    def response(self, flow: http.HTTPFlow):
        # Only process text-like contents
        ctype = flow.response.headers.get("Content-Type", "").lower()
        raw = flow.response.raw_content

        if raw and any(t in ctype for t in ["text", "html", "json"]):
            new_content = raw
            for pattern, repl, t in REWRITE_RULES:
                if t in ctype:
                    new_content, n = pattern.subn(repl, new_content)
                    self.rewrite_count += n

            if new_content != raw:
                flow.response.raw_content = new_content
                # Update Content-Length only if present
                if "Content-Length" in flow.response.headers:
                    flow.response.headers["Content-Length"] = str(len(new_content))
                ctx.log.info(f"Rewrote content ({ctype}); total matches: {self.rewrite_count}")

        ctx.log.info(f"RESP {flow.response.status_code} {flow.request.url}")

addons = [GeorgeProxy()]
Let's run it:
mitmdump -s addon.py
[21:46:04.435] Loading script addon.py
[21:46:04.504] GeorgeProxy addon loaded.
[21:46:04.506] HTTP(S) proxy listening at *:8080.
[21:46:18.547][127.0.0.1:52128] client connect
[21:46:18.593] REQ GET http://httpbin.org/get
[21:46:18.768][127.0.0.1:52128] server connect httpbin.org:80 (52.44.182.178:80)
[21:46:18.910] RESP 200 http://httpbin.org/get
127.0.0.1:52128: GET http://httpbin.org/get
              << 200 OK 353b
[21:46:19.019][127.0.0.1:52128] client disconnect
[21:46:19.021][127.0.0.1:52128] server disconnect httpbin.org:80 (52.44.182.178:80)
Let's see the result:
curl -x http://127.0.0.1:8080 http://httpbin.org/get
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "Proxy-Connection": "Keep-Alive",
    "User-Agent": "curl/8.13.0",
    "X-Amzn-Trace-Id": "Root=1-692c9f0b-7eaf43e61f276ee62b089933",
    "X-Debug-Proxy": "mitm",
    "X-George-Tool": "true"
  },
  "origin": "84.117.220.94",
  "url": "http://httpbin.org/get"
}
This means
The request successfully went through mitmproxy running on 127.0.0.1:8080. Your addon worked: it injected the custom headers (X-Debug-Proxy, X-George-Tool). The httpbin.org echoed back the request details, showing exactly what the server received.

Python 3.13.0 : Tornado - part 001.

Python Tornado is a high‑performance web framework and asynchronous networking library designed for extreme scalability and real‑time applications. Its standout capability is handling tens of thousands of simultaneous connections efficiently, thanks to non‑blocking I/O.
This is an open source project actively maintained and available on tornadoweb.org.

Python Tornado – Key Capabilities

  • Massive Concurrency: Tornado can scale to tens of thousands of open connections without requiring huge numbers of threads.
  • Non‑blocking I/O: Its asynchronous design makes it ideal for apps that need to stay responsive under heavy load.
  • WebSockets Support: Built‑in support for WebSockets enables real‑time communication between clients and servers.
  • Long‑lived Connections: Perfect for long polling, streaming, or chat applications where connections remain open for extended periods.
  • Coroutines & Async/Await: Tornado integrates tightly with Python’s asyncio, allowing developers to write clean asynchronous code using coroutines.
  • Versatile Use Cases: Beyond web apps, Tornado can act as an HTTP client/server, handle background tasks, or integrate with other services.
Tornado setup: The script creates a web server using the Tornado framework, listening on port 8888.
Route definition: A single route /form is registered, handled by the FormHandler class.
GET request: When you visit http://localhost:8888/form, the server responds with an HTML page (form.html) that contains a simple input form.
POST request: When the form is submitted, the post() method retrieves the value of the name field using self.get_argument("name").
Response: The server then sends back a personalized message
Let's see the script:
import tornado.ioloop
import tornado.web
import os

class FormHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("form.html")  # Render an HTML form

    def post(self):
        name = self.get_argument("name")
        self.write(f"Hello, {name}!")

def make_app():
    return tornado.web.Application([
        (r"/form", FormHandler),
    ],
    template_path=os.path.join(os.path.dirname(__file__), "templates")  # <-- aici
    )

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    print("Server pornit pe http://localhost:8888/form")
    tornado.ioloop.IOLoop.current().start()

Thursday, October 30, 2025

Python 3.13.0 : xAI A.P.I. with regional endpoint on xai_sdk python package.

Grok is a family of Large Language Models (LLMs) developed by xAI.
Inspired by the Hitchhiker's Guide to the Galaxy, Grok is a maximally truth-seeking AI that provides insightful, unfiltered truths about the universe.
xAI offers an API for developers to programmatically interact with our Grok models. The same models power our consumer facing services such as Grok.com, the iOS and Android apps, as well as Grok in X experience.
If you want to use a regional endpoint, you need to specify the endpoint url when making request with SDK. In xAI SDK, this is specified through the api_host parameter.
Is not free models available for xAI A.P.I.
See this example from the official website:
import os

from xai_sdk import Client
from xai_sdk.chat import user

client = Client(
api_key=os.getenv("XAI_API_KEY"),
api_host="us-east-1.api.x.ai" # Without the https://
)

chat = client.chat.create(model="grok-4")
chat.append(user("What is the meaning of life?"))

completion = chat.sample()