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

Uploaded Source

Built Distribution

safeIO-1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: safeIO-1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.8.1

File hashes

Hashes for safeIO-1.0.tar.gz
Algorithm Hash digest
SHA256 5ff6247e13b7a154650875f19ae340fd68502c62f4700ce6fd50e0a6d65ee213
MD5 28383c916434e6f6fed8c39dbfc7ac2c
BLAKE2b-256 869e407f754bbf60e06c511274a92636acd564b4bfa78cb2a0f3cf19b6703a9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: safeIO-1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.8.1

File hashes

Hashes for safeIO-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a09296c724e76cd6d92dd6c4cc9af130d24fcdcf23839801e210068b87337ebf
MD5 f6ecba86c568d8c851e187eb341f1809
BLAKE2b-256 a401d8426fd9bcdf2b6568be257c30d06f54059fb7cf4f63d41e688e01f05185

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