py library

1.11.0 · active · verified Sat Mar 28

The 'py' library provides a collection of powerful, low-level utilities primarily focused on filesystem path manipulation, INI parsing, I/O, Python code introspection, and logging. Maintained by the pytest-dev team, it often serves as a foundational component for other testing and development tools. It is currently at version 1.11.0 and has a stable release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic file system operations using `py.path.local`, including creating a directory, writing to a file, reading from it, and cleaning up. This highlights the object-oriented approach to path manipulation provided by the `py` library.

import py
import os

# Create a temporary local path object
temppath = py.path.local('my_temp_dir')
temppath.ensure(dir=True) # Ensure it's a directory

# Join paths and write content
filepath = temppath.join('hello.txt')
filepath.write('Hello, py world!')

# Read content
print(filepath.read())

# Cleanup
filepath.remove()
temppath.remove()

view raw JSON →