Skip to main content

Common functions for working in Python

Project description

Harrix PyLib

Featured image

๐Ÿ Common Python functions (3.10+) library for my projects for my projects.

๐Ÿ“– Contents โฌ‡๏ธ

Contents

GitHub GitHub PyPI

GitHub: https://github.com/Harrix/harrix-pylib

Documentation: docs

โœจ Features

  • ๐Ÿ“ File Operations - Directory management, file processing, archive handling
  • ๐Ÿ“ Markdown Tools - YAML processing, TOC generation, content manipulation
  • ๐Ÿ”ง Development Utils - Project setup, code formatting, documentation generation
  • ๐Ÿ›ก๏ธ Code Checkers - Custom validation rules for Python and Markdown (complements standard linters)

๐Ÿ“ฆ Installation

Using pip:

pip install harrix-pylib

Using uv (recommended):

uv add harrix-pylib

๐Ÿƒ Quick start

Examples of using the library:

import harrixpylib as h

h.file.clear_directory("C:/temp_dir")
import harrixpylib as h

md_clean = h.file.remove_yaml_content("""
---
categories: [it, program]
tags: [VSCode, FAQ]
---

# Installing VSCode
""")
print(md_clean)  # Installing VSCode

๐Ÿ“š List of functions

๐Ÿ“„ File funcs_dev.py

Doc: funcs_dev.g.md

Function/Class Description
๐Ÿ”ง get_project_root Find the root folder of the current project.
๐Ÿ”ง load_config Load configuration from a JSON file.
๐Ÿ”ง run_command Run a console command and return its output.
๐Ÿ”ง run_powershell_script Run a PowerShell script with the given commands.
๐Ÿ”ง run_powershell_script_as_admin Execute a PowerShell script with administrator privileges and captures the output.
๐Ÿ”ง write_in_output_txt Decorate to write function output to a temporary file and optionally display it.

๐Ÿ“„ File funcs_file.py

Doc: funcs_file.g.md

Function/Class Description
๐Ÿ”ง all_to_parent_folder Move all files from subfolders within the given path to the parent folder and then
๐Ÿ”ง apply_func Recursively apply a function to all files with a specified extension in a directory.
๐Ÿ”ง check_featured_image Check for the presence of featured_image.* files in every child folder, not recursively.
๐Ÿ”ง check_func Recursively applies a checking function to all files with a specified extension in a directory.
๐Ÿ”ง clear_directory Clear directory with sub-directories.
๐Ÿ”ง extract_zip_archive Extract ZIP archive to the folder where the archive is located and remove the archive file.
๐Ÿ”ง find_max_folder_number Find the highest folder number in a given folder based on a pattern.
๐Ÿ”ง list_files_simple Generate a simple list of all files in a directory structure.
๐Ÿ”ง open_file_or_folder Open a file or folder using the operating system's default application.
๐Ÿ”ง remove_empty_folders Remove all empty folders recursively while respecting ignore patterns.
๐Ÿ”ง rename_epub_file Rename EPUB file based on metadata from file content.
๐Ÿ”ง rename_fb2_file Rename FB2 file based on metadata from file content.
๐Ÿ”ง rename_file_spaces_to_hyphens Rename file by replacing spaces with hyphens in the filename.
๐Ÿ”ง rename_files_by_mapping Rename files recursively based on a mapping dictionary while respecting ignore patterns.
๐Ÿ”ง rename_largest_images_to_featured Find the largest image in each subdirectory of the given path and renames it to 'featured-image'.
๐Ÿ”ง rename_pdf_file Rename PDF file based on metadata from file content.
๐Ÿ”ง should_ignore_path Check if a path should be ignored based on common ignore patterns.
๐Ÿ”ง tree_view_folder Generate a tree-like representation of folder contents.

๐Ÿ“„ File funcs_md.py

Doc: funcs_md.g.md

Function/Class Description
๐Ÿ”ง add_diary_entry_in_year Add a new diary entry to the yearly Markdown file.
๐Ÿ”ง add_diary_new_dairy_in_year Add a new diary entry to the yearly diary file.
๐Ÿ”ง add_diary_new_diary Create a new diary entry for the current day and time.
๐Ÿ”ง add_diary_new_dream Create a new dream diary entry for the current day and time with placeholders for dream descriptions.
๐Ÿ”ง add_diary_new_dream_in_year Add a new dream diary entry to the yearly dream file.
๐Ÿ”ง add_diary_new_note Add a new note to the diary or dream diary for the given base path.
๐Ÿ”ง add_note Add a note to the specified base path.
๐Ÿ”ง append_path_to_local_links_images_line Append a path to local links and images within a Markdown line.
๐Ÿ”ง combine_markdown_files Combine multiple Markdown files in a folder into a single file with intelligent YAML header merging.
๐Ÿ”ง combine_markdown_files_recursively Recursively process a folder structure and combines Markdown files in each folder that meets specific criteria.
๐Ÿ”ง delete_g_md_files_recursively Delete all *.g.md files recursively in the specified folder.
๐Ÿ”ง download_and_replace_images Download remote images in Markdown text and replaces their URLs with local paths.
๐Ÿ”ง download_and_replace_images_content Download remote images in Markdown text and replaces their URLs with local paths.
๐Ÿ”ง format_quotes_as_markdown_content Convert raw text with quotes into Markdown format.
๐Ÿ”ง format_yaml Format YAML content in a file, ensuring proper indentation and structure.
๐Ÿ”ง format_yaml_content Format the YAML front matter within the given Markdown text.
๐Ÿ”ง generate_author_book Add the author and the title of the book to the quotes and formats them as Markdown quotes.
๐Ÿ”ง generate_id Return exactly the same anchor slug GitHub creates for a Markdown heading.
๐Ÿ”ง generate_image_captions Process a Markdown file to add captions to images based on their alt text.
๐Ÿ”ง generate_image_captions_content Generate image captions in the provided Markdown text.
๐Ÿ”ง generate_short_note_toc_with_links Generate a separate Markdown file with only the Table of Contents (TOC) from a given Markdown file.
๐Ÿ”ง generate_short_note_toc_with_links_content Generate a Markdown content with only the Table of Contents (TOC) from a given Markdown text.
๐Ÿ”ง generate_summaries Generate two summary files for a directory of year-based Markdown files.
๐Ÿ”ง generate_toc_with_links Generate a Table of Contents (TOC) with clickable links for a given Markdown file and inserts or refreshes
๐Ÿ”ง generate_toc_with_links_content Generate a Table of Contents (TOC) with links for the provided Markdown content.
๐Ÿ”ง get_yaml_content Get YAML from text of the Markdown file.
๐Ÿ”ง identify_code_blocks Process a sequence of text lines to identify code blocks and yield each line with a boolean flag.
๐Ÿ”ง identify_code_blocks_line Parse a single line of Markdown to identify inline code blocks.
๐Ÿ”ง increase_heading_level_content Increase the heading level of Markdown content.
๐Ÿ”ง remove_markdown_formatting_for_headings Remove markdown formatting from text.
๐Ÿ”ง remove_toc_content Remove the table of contents (TOC) section from a Markdown document.
๐Ÿ”ง remove_yaml_and_code_content Remove YAML front matter and code blocks, and returns the remaining content.
๐Ÿ”ง remove_yaml_content Remove YAML from text of the Markdown file.
๐Ÿ”ง replace_section Replace a section in a file defined by title_section with the provided replace_content.
๐Ÿ”ง replace_section_content Replace a section in the Markdown text defined by title_section with the provided replace_content.
๐Ÿ”ง sort_sections Sort the sections of a Markdown file by their headings, maintaining YAML front matter
๐Ÿ”ง sort_sections_content Sort sections by their ## headings: top sections first, then dates in descending order,
๐Ÿ”ง split_toc_content Separate the Table of Contents (TOC) from the rest of the Markdown content.
๐Ÿ”ง split_yaml_content Split a Markdown note into YAML front matter and the main content.

๐Ÿ“„ File funcs_py.py

Doc: funcs_py.g.md

Function/Class Description
๐Ÿ”ง create_uv_new_project Create a new project using uv, initializes it, and sets up necessary files.
๐Ÿ”ง extract_functions_and_classes Extract all classes and functions from a Python file and formats them into a Markdown list.
๐Ÿ”ง generate_md_docs Generate documentation for all Python files within a given project folder.
๐Ÿ”ง generate_md_docs_content Generate Markdown documentation for a single Python file.
๐Ÿ”ง lint_and_fix_python_code Lints and fixes the provided Python code using the ruff formatter.
๐Ÿ”ง sort_py_code Sorts the Python code in the given file by organizing classes, functions, and statements.

๐Ÿ“„ File markdown_checker.py

Doc: markdown_checker.g.md

Function/Class Description
๐Ÿ›๏ธ Class MarkdownChecker Class for checking Markdown files for compliance with specified rules.

๐Ÿ“„ File python_checker.py

Doc: python_checker.g.md

Function/Class Description
๐Ÿ›๏ธ Class PythonChecker Class for checking Python files for compliance with specified rules.

๐Ÿ“„ License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

harrix_pylib-0.169.tar.gz (167.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

harrix_pylib-0.169-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file harrix_pylib-0.169.tar.gz.

File metadata

  • Download URL: harrix_pylib-0.169.tar.gz
  • Upload date:
  • Size: 167.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for harrix_pylib-0.169.tar.gz
Algorithm Hash digest
SHA256 b2612095ca1de329a130990cdda530577f42483389dd04b8bcd8a29455468ce0
MD5 1957fcaec97bf17997e1a6e6be8d48c4
BLAKE2b-256 a89cc47f0475c4d02c1debadf444213a94b2ffc59789bac8f56c76f5b8383719

See more details on using hashes here.

File details

Details for the file harrix_pylib-0.169-py3-none-any.whl.

File metadata

File hashes

Hashes for harrix_pylib-0.169-py3-none-any.whl
Algorithm Hash digest
SHA256 dfff76a95d4fd641d0afcd0780674108f8ea45aa4ddd6554916bf24ff729c496
MD5 40cd3e720f98d4d8e171249ed28a1599
BLAKE2b-256 5c172448eefdaa22c05a01306894d08765cfaec818181dcc17021c203cbc8509

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page