{"id":6780,"library":"provide-dir","title":"Provide Directory","description":"The `provide-dir` library is a lightweight utility that ensures a given directory path exists, creating all necessary parent directories if they don't. It's built on top of `os.makedirs` and offers a simplified interface. Currently at version 0.1.2, it follows an infrequent but steady release cadence, with updates typically several months apart.","status":"active","version":"0.1.2","language":"en","source_language":"en","source_url":"https://github.com/Nagidal/provide_dir","tags":["filesystem","directory","utility","path"],"install":[{"cmd":"pip install provide-dir","lang":"bash","label":"Install provide-dir"}],"dependencies":[],"imports":[{"symbol":"provide_dir","correct":"from provide_dir import provide_dir"}],"quickstart":{"code":"from provide_dir import provide_dir\nimport os\n\n# Define a test directory path\nbase_dir = os.environ.get('TEST_BASE_DIR', 'temp_test_dir')\ndir_path = os.path.join(base_dir, 'my', 'nested', 'directory')\n\nprint(f\"Attempting to create: {dir_path}\")\n\n# Create the directory and all its parents\ncreated_path = provide_dir(dir_path)\n\nprint(f\"Directory ensured at: {created_path}\")\nprint(f\"Does the directory exist? {os.path.isdir(created_path)}\")\n\n# Clean up (optional)\n# import shutil\n# shutil.rmtree(base_dir)\n","lang":"python","description":"This quickstart demonstrates how to use `provide_dir` to create a nested directory structure. It will create `temp_test_dir/my/nested/directory` and print the resulting path. The `os.environ.get` ensures it's runnable without specific environment setup."},"warnings":[{"fix":"Pass an explicit `mode` argument: `provide_dir('/path/to/dir', mode=0o755)`","message":"The `mode` argument (permissions) defaults to `0o777` (world-writable), which might be too permissive for certain environments or security requirements. Always explicitly set `mode` (e.g., `0o755`) if specific permissions are needed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `exist_ok=True` (which is the default) if you want the function to succeed silently when the directory already exists. If you need to detect existing directories, handle `FileExistsError`.","message":"If `exist_ok` is set to `False` (the default is `True`), a `FileExistsError` will be raised if the target directory already exists. This can be unexpected if you assume it will always succeed for existing paths.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For file paths, extract the directory part before calling `provide_dir`: `provide_dir(os.path.dirname('path/to/file.txt'))`.","message":"This function is designed to create directories. If you provide a path that is intended to be a *file* (e.g., `path/to/file.txt`), `provide_dir` will create `path/to/file.txt` as a *directory*, not just its parent `path/to`. To create parent directories for a file, use `os.path.dirname` first.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}