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.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: safeIO-1.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.1.tar.gz
Algorithm Hash digest
SHA256 4fbe789250cf7edddddcd5d5f7ac696afc8815b0cabfa0e4d67e682b8d4c38cd
MD5 0e9cd1695eedf67c7cd172913ab44dd7
BLAKE2b-256 d587fa97521767d6a3de79667055b774818968af551ee764268ed4d5a2dcfecf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: safeIO-1.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a350e25500bfb997c58ddee88ff6ddac118457ffe19f47b022f2e7266cef813
MD5 f66611081959c791872396bb022b2e7d
BLAKE2b-256 ba708e414eb58fa3b64d6450d51167da5ea628f01370d22c6aac080234789f38

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