A library for file information and manipulation
Project description
infila
infila is a Python library designed for file operations. It provides various functions to retrieve information about files, including their size, creation and modification times, type, line count, and encoding.
Installation
You can install the infila library using pip:
pip install infila
What's new in version 0.1.3?
infila received the final update for its full release 0.1.3, which includes standard features:
- File size in specified unit via get_size
- File creation time via get_creation_time
- File modification time via get_modification_time
- File type via get_file_type
- Number of lines in the file via count_lines
- File encoding via detect_encoding
- File attributes via get_attributes
- Previous versions via get_previous_versions (temporarily unavailable)
- File security via get_security
- SHA-256 sum via get_sha256
Manual
Initialization
To begin, create an instance of infila by passing the file path as a parameter:
file = infila("path/to/your/file")
Methods
Below are the main methods available in the infila class:
get_size(unit='bytes')
Description: Returns the size of the file in the specified unit. Parameters:
- unit (str): Unit for file size. Options include 'bits', 'bytes', 'kilobytes', 'megabytes', 'gigabytes', and 'terabytes'.
Returns: File size in the specified unit. Example:
size_in_kb = file.get_size('kb')
get_creation_time()
Description: Retrieves the creation time of the file. Returns: Creation time as a formatted string. Example:
creation_time = file.get_creation_time()
get_modification_time()
Description: Retrieves the last modification time of the file. Returns: Modification time as a formatted string. Example:
modification_time = file.get_modification_time()
get_file_type()
Description: Returns the file extension type. Returns: File extension as a string. Example:
file_type = file.get_file_type()
count_lines()
Description: Counts the number of lines in the file (assumes UTF-8 encoding). Returns: Integer count of lines in the file. Example:
line_count = file.count_lines()
detect_encoding()
Description: Detects the encoding of the file using the chardet library. Returns: Detected file encoding as a string. Example:
encoding = file.detect_encoding()
get_attributes()
Description: Retrieves attributes of the file, such as readability, writability, executability, owner ID, and permissions. Returns: Dictionary containing file attributes. Example:
attributes = file.get_attributes()
get_previous_versions()
Description: Placeholder method to retrieve previous file versions. Currently unsupported. Returns: String stating that previous versions are not supported. Example:
previous_versions = file.get_previous_versions()
check_security()
Description: A convenience method to check file security attributes. Returns: Security-related attributes (similar to get_attributes). Example:
security_attributes = file.check_security()
get_sha256()
Description: Calculates and returns the SHA-256 checksum of the file for verification purposes. Returns: SHA-256 hash as a hexadecimal string. Example:
file_hash = file.get_sha256()
Example Usage
file = infila("example.txt")
# Get file size in kilobytes
print("Size (KB):", file.get_size('kb'))
# Get creation and modification times
print("Creation Time:", file.get_creation_time())
print("Modification Time:", file.get_modification_time())
# Get file type and line count
print("File Type:", file.get_file_type())
print("Line Count:", file.count_lines())
# Detect encoding
print("Encoding:", file.detect_encoding())
# Get file attributes
print("Attributes:", file.get_attributes())
# Calculate SHA-256 checksum
print("SHA-256 Checksum:", file.get_sha256())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infila_python-0.1.3.tar.gz.
File metadata
- Download URL: infila_python-0.1.3.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fa3dbb1809f64b8ee733f8e3e5b5fbcb3664e97788551dc7b82d1d7242e3ce4
|
|
| MD5 |
85347fa1f368597a914863f9265928ed
|
|
| BLAKE2b-256 |
8b60306368df7c12c02b411678b72914aef09bb3ac9ffd651edc476fac69f019
|
File details
Details for the file infila_python-0.1.3-py3-none-any.whl.
File metadata
- Download URL: infila_python-0.1.3-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7569dc1dca18baa5ed076677c2e471899c784d22742f75158257e7b575c4d992
|
|
| MD5 |
35b47413e83d35427cccfd331de8d0e2
|
|
| BLAKE2b-256 |
c2c31cd4c6779a71d3116a93058abab23ecfc4aed341a45fa945eb8d0b671c22
|