{"id":4679,"library":"pathmagic","title":"Pathmagic","description":"Pathmagic provides Object-Relational Mapping (ORM) style path classes, `File` and `Dir`, which automatically execute file system I/O operations when their attributes are modified. This approach aims to abstract away common filesystem interactions, offering an intuitive way to manipulate files and directories, including easy content management for various file types. The library is currently at version 0.3.14 and maintains an active development pace with frequent minor releases.","status":"active","version":"0.3.14","language":"en","source_language":"en","source_url":"https://github.com/matthewgdv/pathmagic","tags":["filesystem","ORM","path","file-management","declarative"],"install":[{"cmd":"pip install pathmagic","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"File","correct":"from pathmagic import File"},{"symbol":"Dir","correct":"from pathmagic import Dir"}],"quickstart":{"code":"from pathmagic import File, Dir\nimport os\n\n# Ensure a directory exists for demonstration\ntemp_dir_name = \"pathmagic_demo_dir\"\nif not os.path.exists(temp_dir_name):\n    os.makedirs(temp_dir_name)\nprint(f\"Working in directory: {temp_dir_name}\")\n\n# 1. Create a File object and write content\nmy_file_path = os.path.join(temp_dir_name, \"my_document.txt\")\nmy_file = File(my_file_path)\nmy_file.content = \"Hello, pathmagic world!\\nThis is a test.\"\nprint(f\"Created file at: {my_file.path} and wrote content.\")\n\n# 2. Read content from the File object\nread_content = my_file.content\nprint(f\"Read content: \\\"{read_content.strip()}\\\"\")\n\n# 3. Modify a file attribute, triggering a filesystem operation (e.g., rename)\nold_path = my_file.path\nmy_file.name = \"renamed_document.txt\" # This automatically renames the file on disk\nprint(f\"File renamed from '{old_path}' to '{my_file.path}'\")\n\n# 4. Demonstrate a Dir object\nmy_dir = Dir(temp_dir_name)\nprint(f\"Directory object created for: {my_dir.path}\")\n\n# Clean up\nos.remove(my_file.path)\nos.rmdir(temp_dir_name)\nprint(\"Cleaned up demo files and directory.\")","lang":"python","description":"This quickstart demonstrates the core functionality of `pathmagic.File` and `pathmagic.Dir` by creating a temporary directory and file, writing content, reading it back, and performing a rename operation via attribute modification. The `File` and `Dir` objects abstract away direct `os` or `pathlib` calls for these operations."},"warnings":[{"fix":"Monitor GitHub releases and the PyPI project page for API change announcements. Consider pinning specific minor versions if stability is critical.","message":"The `pathmagic` library is currently under active development, and its API is subject to significant changes that may introduce breaking changes in future versions. Code written with the current API may require adjustments.","severity":"breaking","affected_versions":"All versions prior to a stable 1.0 release (currently 0.x.x)"},{"fix":"Refer directly to the source code on GitHub for the most up-to-date understanding of the API and behavior if documentation appears to be insufficient or outdated.","message":"The documentation for `pathmagic` may fall out of sync with updates due to the rapid development pace. Users might encounter undocumented features or outdated examples.","severity":"gotcha","affected_versions":"All versions prior to a stable 1.0 release (currently 0.x.x)"},{"fix":"Double-check `pip install` commands and `import` statements to ensure they reference `pathmagic` if you intend to use the ORM-style path objects, not `python-magic`.","message":"This `pathmagic` library (for ORM-like filesystem objects) is frequently confused with the `python-magic` library (a Python interface to the `libmagic` file type identification library). Ensure you are installing and importing the correct package for your intended use case.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}