Skip to main content

Common functions for working in Python

Project description

harrix-pylib

Featured image

This is a Python library containing common functions for working in Python (>= 3.10) for my projects.

📖 Contents

Contents

GitHub GitHub PyPI

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

Documentation: docs

Install

  • pip: pip install harrix-pylib
  • uv: 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.
find_max_folder_number Find the highest folder number in a given folder based on a pattern.
open_file_or_folder Open a file or folder using the operating system's default application.
rename_largest_images_to_featured Find the largest image in each subdirectory of the given path and renames it to 'featured-image'.
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_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_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

License: MIT.

Project details


Release history Release notifications | RSS feed

This version

0.168

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.168.tar.gz (136.2 kB view details)

Uploaded Source

Built Distribution

harrix_pylib-0.168-py3-none-any.whl (49.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for harrix_pylib-0.168.tar.gz
Algorithm Hash digest
SHA256 28c7adaf60de3df0afd9f53d68757eba29d4d211ea1801617bea16b248ff7755
MD5 b441558abf9d4317f366c87dcb9e827e
BLAKE2b-256 29d7d5e4d52403a4a9ed2335348d158d98bed3f1c1e76e84e1c9efb7f80fa152

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for harrix_pylib-0.168-py3-none-any.whl
Algorithm Hash digest
SHA256 da7cc864d7f91092bedefddfdf0d28c8b8bea7cf3ed42dbdd56d11a39a8aa771
MD5 8f31c08e9a275a55c651eebb75c18ec3
BLAKE2b-256 201daf70a4f96666b7ed6fbf414a178d28d654a17a587ba0167d14e5220665d7

See more details on using hashes here.

Supported by

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