Skip to main content

Safely make I/O operations to files in Python even from multiple threads... and more!

Project description

safeIO

Safely make I/O operations to files in Python even from multiple threads... and more!

Table of Content

  1. safeIO
  2. Table of Content
  3. What is it?
  4. Installation
  5. Objects

What is it?

It's a module which lets you manage your files (most of the time, Input/Output operations) without worrying about accessing the file from two simultaneously.

Some functions may help you managing your files more easily as they are intuitive and things like substractions (TextFile object - TextFile Object returns the Cosine Similarity of the two files), equality (Object == Object), iteration (for line in TextFile object), the rename/move/delete methods are made easier!.

Installation

From PIP

pip install safeIO --upgrade

Objects

TextFile()

A Text File object

isfile

isfile(callback=None)

Wether the file exists on the disk or not

delete

delete(callback=None)

Deletes the file

rename

rename(newName,overwrite=False,callback=None)

Renames the file and returns its new path

move

move(newPath,overwrite=False,callback=None)

Moves the file and returns its new path

name

name(callback=None)

Returns the file name

fileno

fileno(callback=None)

Returns the file descriptor (int) used by Python to request I/O operations from the operating system.

read

read(position=0,callback=None)

Reads the entire file and returns its content

write

write(data,position=0,callback=None)

Writes (or overwrites) to the file and returns the number of characters written

append

append(data,callback=None)

Appends to the file and returns the number of characters written

readline

readline(position=0,callback=None)

Returns the line of the current position (from the position to the linebreak)

readlines

readlines(position=0,callback=None)

Reads the whole file and returns the lines (separated by a line break)

writelines

writelines(data,position=0,callback=None)

Writes (or overwrites) the given list of lines to the file

appendlines

appendlines(data,callback=None)

Appends the given list of lines to the file

detach

detach(mode="r",callback=None)

Returns the opened IO (TextIOWrapper)

Warning: Make sure to close the file correctly after using the file with detach


BinaryFile()

A Binary File object

isfile

isfile(callback=None)

Wether the file exists on the disk or not

delete

delete(callback=None)

Deletes the file

rename

rename(newName,overwrite=False,callback=None)

Renames the file and returns its new path

move

move(newPath,overwrite=False,callback=None)

Moves the file and returns its new path

name

name(callback=None)

Returns the file name

fileno

fileno(callback=None)

Returns the file descriptor (int) used by Python to request I/O operations from the operating system.

read

read(position=0,callback=None)

Reads the entire file and returns its content

write

write(data,position=0,callback=None)

Writes (or overwrites) to the file and returns the number of bytes written

append

append(data,callback=None)

Appends to the file and returns the number of bytes written

readline

readline(position=0,callback=None)

Returns the line of the current position (from the position to the linebreak)

readlines

readlines(position=0,callback=None)

Reads the whole file and returns the lines (separated by a line break)

writelines

writelines(data,position=0,callback=None)

Writes (or overwrites) the given list of lines to the file

appendlines

appendlines(data,callback=None)

Appends the given list of lines to the file

detach

detach(mode="rb",callback=None)

Returns the opened IO (TextIOWrapper)

Tips: Make sure to include the "b" access mode in the mode\n

Warning: Make sure to close the file correctly after using the file with detach


JSONFile()

A JSON File object

isfile

isfile(callback=None)

Wether the file exists on the disk or not

delete

delete(callback=None)

Deletes the file

rename

rename(newName,overwrite=False,callback=None)

Renames the file and returns its new path

move

move(newPath,overwrite=False,callback=None)

Moves the file and returns its new path

name

name(callback=None)

Returns the file name

fileno

fileno(callback=None)

Returns the file descriptor (int) used by Python to request I/O operations from the operating system.

read

read(position=0,callback=None)

Reads the entire file and returns its content

write

write(data,position=0,callback=None)

Writes (or overwrites) to the file and returns the number of characters written

append

append(data,callback=None)

Appends to the file and returns the number of characters written

detach

detach(mode="r",callback=None)

Returns the opened IO (TextIOWrapper)

Warning: Make sure to close the file correctly after using the file with detach

Markdown File | 325 lines

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safeIO-1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

safeIO-1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file safeIO-1.1.tar.gz.

File metadata

  • Download URL: safeIO-1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for safeIO-1.1.tar.gz
Algorithm Hash digest
SHA256 83d106df1ce971ca0b691929fd4369e7e79436789e3070ff2e7a7deee956819d
MD5 adc6d47fa01eff69ffc6eb31f1cb6628
BLAKE2b-256 5aa9db8fac5026d3135df09dead641fb5e41ebdbf27f5da63be7f9992691753f

See more details on using hashes here.

File details

Details for the file safeIO-1.1-py3-none-any.whl.

File metadata

  • Download URL: safeIO-1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.23.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for safeIO-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79bb2c20793373b54d7555e936d01638ce125f6cd89d7a689be3d860eb16c8be
MD5 e8b079863f9479668bd9454e9a3b3fd6
BLAKE2b-256 ed35e1afbb2accb21630425a1bbd7748b8344cd044f0e315a961dc92bc58c320

See more details on using hashes here.

Supported by

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