Open the file pointed to in bytes mode, write data to it, and close the file:
Path.write_bytes(data)
>>> p = Path('my_binary_file') >>> p.write_bytes(b'Binary file contents') 20 >>> p.read_bytes() b'Binary file contents'