Metadata-Version: 2.5
Name: inpsPyPI
Version: 2.0.0
Summary: PyPI package designed to make development in Python easier.
Project-URL: Homepage, https://github.com/isaiahnoelpulidosalazar/inpsPyPI
Author-email: Isaiah Noel Pulido Salazar <isaiahnoelpulidosalazar@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: excel
Requires-Dist: openpyxl>=3.1; extra == 'excel'
Description-Content-Type: text/markdown

# inpsPyPI

`inpsPyPI` is a multipurpose Python utility library providing database wrappers, Excel automation tools, custom data structures, classical cryptography ciphers, sorting algorithms, type converters, and validation helpers.

---

## Installation

```bash
pip install inpsPyPI            # core library (no third-party dependencies)
pip install "inpsPyPI[excel]"   # adds openpyxl for the excellent_reader module
```

Top-level imports are lazy, so `import inpsPyPI` is nearly free; modules load on first use.

---

## Table of Contents
- [Data Structures & Collections](#data-structures--collections)
  - [Dictionarily](#dictionarily)
  - [Memory](#memory)
  - [Stackily](#stackily)
- [Database & File I/O](#database--file-io)
  - [EasySQL](#easysql)
  - [Excellent Reader (Excel Helper)](#excellent-reader-excel-helper)
  - [SimpleFileHandler](#simplefilehandler)
- [Algorithms & Cryptography](#algorithms--cryptography)
  - [Cipher](#cipher)
  - [Sort](#sort)
- [Validation & Utilities](#validation--utilities)
  - [Calculators](#calculators)
  - [Check](#check)
  - [Convert](#convert)
  - [Flask Jsonify Helper (`bake`)](#flask-jsonify-helper-bake)
- [Running Unit Tests](#running-unit-tests)
- [Migrating to 2.0](#migrating-to-20)

---

## Data Structures & Collections

### Dictionarily

A wrapper around standard Python dictionaries with custom sorting capabilities.

```python
from inpsPyPI import Dictionarily

d = Dictionarily()
d.add("b", 2)
d.add("a", 1)
d.add(2, "two")
d.add(1, "one")

# Sort lexicographically by key/value representation
d.sort()

# Sort with numerical keys preceding string keys
d.sort_numbers_first()

# Retrieve internal dict
print(d.show())  # {1: 'one', 2: 'two', 'a': 1, 'b': 2}
```

---

### Memory

A dynamic in-memory list storage container.

```python
from inpsPyPI import Memory

mem = Memory()
mem.add("data1")
mem.add("data2")

count = mem.count()             # 2 (also len(mem))
exists = mem.contains("data1")  # True (also "data1" in mem)
item = mem.get(0)               # "data1"

mem.remove("data1")             # Removes first matching element
mem.remove_at(0)                # Removes (and returns) element by index
mem.clear()                     # Resets internal storage
```

---

### Stackily

A LIFO (Last-In, First-Out) stack implementation.

```python
from inpsPyPI import Stackily

stack = Stackily()
stack.push("first")
stack.push("second")

top_item = stack.peek()        # "second" (does not remove)
popped = stack.pop()           # "second" (removed and returned)
size = stack.size()            # 1
empty = stack.is_empty()       # False
items_list = stack.to_list()   # ["first"] (a copy)
```

`pop()` and `peek()` raise `IndexError` on an empty stack.

---

## Database & File I/O

### EasySQL

A lightweight SQLite helper that abstracts SQL boilerplate with dictionaries. Table and column names must be valid identifiers (`[A-Za-z_][A-Za-z0-9_]*`); they are validated and quoted. Values are always parameterized.

```python
from inpsPyPI import EasySQL

# Connects to 'app_database.db'
sql = EasySQL("app_database")

sql.create_table("users", {
    "id": "INTEGER PRIMARY KEY",
    "name": "TEXT",
    "email": "TEXT"
})

sql.insert_to_table("users", {"id": 1, "name": "Alice", "email": "alice@example.com"})

# Bulk insert: one connection and one transaction for all rows
sql.insert_many("users", [
    {"id": 2, "name": "Bob", "email": "bob@example.com"},
    {"id": 3, "name": "Cara", "email": "cara@example.com"},
])

rows = sql.get_table_values("users")
sql.print_table("users")

sql.delete_from_table("users", {"id": 1})
sql.clear_table("users")   # DELETE FROM users
sql.delete_table("users")  # DROP TABLE IF EXISTS users
```

---

### Excellent Reader (Excel Helper)

Utilities for reading and writing column data in `.xlsx` files using `openpyxl` (install with `pip install "inpsPyPI[excel]"`). Default `skip_rows=2` skips headers. Empty cells are returned as `""`. Errors such as `FileNotFoundError` or `IndexError` propagate to the caller.

```python
from inpsPyPI import excellent_reader

file = "data.xlsx"

# --- Reading Data ---
first_col = excellent_reader.get_first_column_from_sheet_index(file, index=0, skip_rows=2)
col_b = excellent_reader.get_n_column_from_sheet_index(file, index=0, column="B", skip_rows=2)
all_first_cols = excellent_reader.get_first_column_from_all_sheets(file, skip_rows=2)
all_c_cols = excellent_reader.get_n_column_from_all_sheets(file, column="C", skip_rows=2)

# --- Writing Data ---
excellent_reader.set_first_column_from_sheet_index(file, index=0, value=["Val1", "Val2"], skip_rows=2)
excellent_reader.set_n_column_from_sheet_index(file, index=0, column="B", value="StaticValue", skip_rows=2)
excellent_reader.set_first_column_from_all_sheets(file, value="Updated", skip_rows=2)
excellent_reader.set_n_column_from_all_sheets(file, column="D", value=["Row1", "Row2"], skip_rows=2)

# --- Error handling ---
try:
    excellent_reader.get_first_column_from_sheet_index("missing.xlsx", 0)
except FileNotFoundError:
    ...
```

---

### SimpleFileHandler

Static file I/O operations with default UTF-8 encoding.

```python
from inpsPyPI import SimpleFileHandler

SimpleFileHandler.write("sample.txt", "Hello World")   # overwrites
SimpleFileHandler.append("sample.txt", "\nNext line")
content = SimpleFileHandler.read("sample.txt")
```

---

## Algorithms & Cryptography

### Cipher

Classical text ciphers for uppercase alphabetic characters (spaces and non-alphabetic characters are preserved). Non-letter characters in keywords are ignored; Caesar shifts of any size (including negative) wrap correctly.

```python
from inpsPyPI import Cipher

Cipher.caesar_cipher("HELLO WORLD", 3)                      # 'KHOOR ZRUOG'
Cipher.keyword_cipher("HELLO WORLD", "KEYWORD")             # 'AOGGJ UJNGW'
Cipher.giovanni_cipher("HELLO WORLD", "KEYWORD", "C")       # 'RYCCH SHLCE'
Cipher.transposition_cipher("HELLO WORLD")                  # 'HLOOLELWRD'
```

---

### Sort

A collection of sorting algorithms. **Every function returns a new list and never mutates its input.**

| Function | Description | Supported Input |
| :--- | :--- | :--- |
| `bubble_sort(arr)` | Bubble sort (early exit) | Generic list |
| `cocktail_shaker_sort(arr)` | Bidirectional bubble sort | Generic list |
| `odd_even_sort(arr)` | Odd-even transposition sort | Generic list |
| `selection_sort(arr)` | Selection sort | Generic list |
| `insertion_sort(arr)` | Insertion sort | Generic list |
| `shellsort(arr)` | Shell sort | Generic list |
| `quicksort(arr)` | Quicksort (3-way partition) | Generic list |
| `merge_sort(arr)` | Stable merge sort | Generic list |
| `heapsort(arr)` | Heapsort via `heapq` | Generic list |
| `introsort(arr)` | Quicksort (median-of-3) with heapsort fallback | Generic list |
| `timsort(arr)` | Standard Python Timsort | Generic list |
| `counting_sort(arr)` | Counting sort | Integers (negatives OK) |
| `bucket_sort_uniform(arr)` | Uniform bucket sort | Floats in range $[0.0, 1.0)$ |
| `pigeonhole_sort(arr)` | Pigeonhole sort | Integers (negatives OK) |
| `patience_sorting(arr)` | Patience sorting via piles | Generic list |
| `bogosort(arr)` | Randomized bogo sort (educational; keep lists tiny) | Generic list |
| `bead_sort(arr)` | Gravity / Bead sort | Non-negative integers |

```python
from inpsPyPI import sort

data = [5, 2, 9, 1, 5, 6]
sorted_data = sort.quicksort(data)   # data is unchanged

uniform_floats = [0.89, 0.56, 0.65, 0.12, 0.66]
sorted_floats = sort.bucket_sort_uniform(uniform_floats)
```

---

## Validation & Utilities

### Calculators

Geometric calculations (2D areas, 3D surface areas) and the Collatz sequence. Negative dimensions raise `ValueError`.

```python
from inpsPyPI import AreaCalculator, CollatzCalculator

# --- 2D Shapes ---
AreaCalculator.square_area(4.0)             # 16.0
AreaCalculator.rectangle_area(4.0, 5.0)     # 20.0
AreaCalculator.triangle_area(10.0, 4.0)     # 20.0
AreaCalculator.circle_area(5.0)             # 78.54
AreaCalculator.sector_area(5.0, 60.0)       # 13.09
AreaCalculator.segment_area(5.0, 60.0)      # 2.26

vertices = [(0, 0), (4, 0), (4, 3), (0, 3)]
AreaCalculator.polygon_shoelace_area(vertices)   # 12.0

# --- 3D Surface Areas ---
AreaCalculator.cube_surface_area(3.0)       # 54.0
AreaCalculator.cylinder_surface_area(3.0, 10.0)  # 245.04
AreaCalculator.sphere_surface_area(3.0)     # 113.10

# --- Collatz ---
CollatzCalculator.calculate(6)              # [6, 3, 10, 5, 16, 8, 4, 2, 1]
for n in CollatzCalculator.iterate(27):     # lazy, O(1) memory
    ...
```

---

### Check

Input validation and network connectivity checkers.

```python
from inpsPyPI import Check, EmailDomainValidator

# --- Email validation (recommended: your own validator instance) ---
validator = EmailDomainValidator(names=["gmail"], extensions=["com"])
validator.is_valid("user@gmail.com")        # True (case-insensitive)

full = EmailDomainValidator(domains=["company.co.uk"], use_full_domain=True)
full.is_valid("user@company.co.uk")         # True

# --- Legacy global API (still supported; shares state process-wide) ---
Check.Email.add_valid_domain_name("gmail")
Check.Email.add_valid_domain_extension("com")
Check.Email.should_use_full_domain(False)
Check.Email.is_valid("user@gmail.com")      # True
Check.Email.reset()                         # clear the shared configuration

# --- String analysis ---
Check.is_a_valid_philippine_mobile_number("+639171234567")  # True
Check.is_all_numbers("123456")                              # True
Check.has_numbers("User123")                                # True
Check.has_symbols("hello@world")                            # True
Check.has_spaces("Hello World")                             # True

# --- Network status ---
has_internet = Check.is_connected()  # True if 8.8.8.8:53 is reachable
```

---

### Convert

Type conversions and encoding transformations. Hex and binary conversions operate on UTF-8 bytes, so all characters (including emoji and CJK) round-trip.

```python
from inpsPyPI import Convert

Convert.reverse("python")         # "nohtyp"
Convert.to_real_name("jOHN")      # "John"

b64_str = Convert.to_base64("hello")     # "aGVsbG8="
orig_str = Convert.from_base64(b64_str)  # "hello"

hex_str = Convert.to_hex("hello")        # "68656C6C6F"
from_hex = Convert.from_hex(hex_str)     # "hello"

bin_str = Convert.to_binary("hello")     # "0110100001100101011011000110110001101111"
from_bin = Convert.from_binary(bin_str)  # "hello"

byte_arr = Convert.to_byte_array("hello")      # b'hello'
from_byte = Convert.from_byte_array(byte_arr)  # "hello"

Convert.to_int("100")       # 100
Convert.to_float("3.14")    # 3.14
Convert.to_double("3.14")   # 3.14 (alias of to_float)
Convert.to_long("100000")   # 100000 (alias of to_int)
```

---

### Flask Jsonify Helper (`bake`)

Wraps any payload into a standardized dictionary response.

```python
from inpsPyPI import bake

bake("Success")
# {'response_data': 'Success'}

bake({"status": 200, "user": "admin"})
# {'response_data': {'status': 200, 'user': 'admin'}}
```

---

## Running Unit Tests

```bash
pip install -e ".[excel]" pytest
python -m pytest            # or: python -m unittest discover tests
```

---

## Migrating to 2.0

- `excellent_reader` now **raises** (`FileNotFoundError`, `IndexError`, ...) instead of printing and returning `None`/`False`, and empty cells read as `""` instead of `"NONE"`. It requires `pip install "inpsPyPI[excel]"`.
- Sorting functions never mutate their input; use the returned list.
- `test_method` / `inpsPyPI.test` were removed.
- Hex/binary conversion now encodes UTF-8 bytes (identical output for ASCII).
- `EasySQL` rejects table/column names that are not plain identifiers.
- `Check.Email` still works but is case-insensitive and compares the real TLD; prefer `EmailDomainValidator`.
