Skip to main content

easy to set up alternative to SQl, bugs and leak proof by design and also support multiple console interactions

Project description


# 🧾 A data cleaning and quality solution for messy data, bug prevention, and leakage control.

A lightweight, Python-native, zero-dependency utility for managing structured .txt files. Ideal for structured data storage where full database integration is overkill. Uses simple 1D/2D list logic

---

## 📦 Features

- **Structured Data Enforcement (1D/2D)**
- ✍️ **Write, Read, Append, and Delete Operations with Built-in Validation**
- 🔍 **Sql select style Read filtering**
- 🧹 **Selective Deletes & Trimming**
- 🎗️ **Multi-Console Safe for Concurrent Access**
- 💾 **Manual Backups or Timed Snapshots**
- 🧪 **Debug Tool & Auto-Clean Invalid Rows**
- 🗂️ **Clean Folder & Versioned File Organization**
- 🔐 **File Hiding and Visibility Controls**
- 🗃️ **No External Dependencies**
- 💪 **Strong anti-corruption and Tamper mechanism**
---

## Why Use This Package?

**For Data Professionals (Analysts, Scientists, Engineers):**

* Build quick dashboards and visualizations from real-time text data.
* Process and clean scraped or pipeline data without needing a database.
* Track, audit, and version small datasets during experimentation.
* Validate incoming data and auto-correct format issues on the fly (clean from the source).
* Run fast, repeatable data operations locally without SQL overhead.

**For General Developers:**

* Great for automation scripts, bots, or microservices.
* Ideal for prototyping features without setting up a database.
* Use as a flat-file backend for small apps or CLI tools.
* Snapshot and backup data safely without extra libraries.
* Handle concurrent access and reduce race-condition bugs automatically.

---

## 📦 Installation 
pip install cleandb

## ♻️ Upgrade
pip install --upgrade cleandb

---

## 🚀 Quick Usage

```python

# import
import cleandb as db

# Create a 2D structured file
db.w("tasks", [["Read", "Done"], ["Code", "Pending"]], is2d=True)

# Append to file
db.a("tasks", [["Test", "Pending"]])

# Read all data
db.r("tasks")

# Delete rows where status is "Done"
db.d("tasks", del_list=["Done"], index=1)

# Manual backup
db.backup("tasks")

# Snapshot every 6 hours
db.snapshot("tasks", unit="h", gap=6)
```

---

## 🧰 Function Overview

### 🔄 Write

```python
w(txt_name, write_list, is2d=None)
```

Overwrites data and validates structure. Use `[]` to reset file and structure.

---

### 📖 Read

```python
r(txt_name, index=None, set_new=[], notify_new=True)
```

Reads data or returns `set_new` if file doesn't exist.

---

### ➕ Append

```python
a(txt_name, append_list, is2d=None)
```

Appends new data to file. Must match existing structure.

---

### ❌ Delete

```python
d(txt_name, del_list=[], index=None, cutoff=None, keep=None, reverse=False, size=None)
```

Deletes rows by value, with support for:

* `cutoff`: Max deletions per value
* `keep`: Keep N rows per value
* `reverse`: Reverse traversal
* `size`: Trim file to last N rows

---

### 💾 Backup

```python
backup(txt_name, display=True)
```

Creates manual backup. Use `'*'` to back up all files.

---

### ⏱ Snapshot

```python
snapshot(txt_name, unit, gap, trim=None, begin=0, display=True)
```

Creates a time-based snapshot if the gap is met. Units:

* `'s'`, `'m'`, `'h'`, `'d'`, `'mo'`, `'y'`

---

### 🧹 Debug

```python
debug(txt_name, is2d=None, clean=None, length=None, display=True)
```

Scans file for validation issues and optionally cleans/fixes it.

---

### 🧨 Remove

```python
remove(txt_name, display=True)
```

Permanently deletes file and all backups.

---

### 🙈 Hide / Unhide

```python
hide(txt_name, display=True)
unhide(txt_name, display=True)
```

Hides or unhides files or all files with `'*'`.

---

### 📋 List Files

```python
listdir(display=True)
```

Returns list of all stored file names.

---

### ℹ️ File Info

```python
info(txt_name, display=True)
describe(txt_name, display=True)
```

Shows metadata about file: type, shape, size, etc.

---

## 🧠 Notes

* **Structure Locking**: On first write/append, the shape (1D/2D) and row length (for 2D) is saved.
* Use `w("file", [])` to reset the file and clear the structure lock.
* Only `list` data is supported (1D or 2D).
* All changes sync automatically across backups.
* Files are validated before every write operation.

---

## 🛡 Good Practices

* Always use the provided `w`, `a`, `r`, `d`, etc. functions for access.
* Don't manually edit `.txt` files — structure validation may fail.
* Schedule `snapshot()` calls during long-running processes.
* Use `debug()` if you're unsure why writes are failing.

---

## 🧪 Example Workflow

```python
# Setup
import cleandb as db

# first write / create a new file
db.w("expenses", [["Rent", 1200], ["Food", 300]])

# Add a new expense
db.a("expenses", [["Internet", 60]])

# Show last 2 entries
db.print(r("expenses", index=[-2, -1]))

# Remove "Food" entry
db.d("expenses", del_list=["Food"], index=0)

# Take a snapshot every 24 hours
db.snapshot("expenses", unit="d", gap=1 , trim = 12)
```

---

## 📂 Backup & Recovery

* Backups are stored under `Backup 💾/`
* Snapshots are stored under `Snapshot 📸/`
* To restore, simply copy the file back to main data directory

---

## 📜 License

This project is free to use, modify, and distribute. No warranty is provided.

---

## 🙋 Contribution

Feel free to fork, improve, and send pull requests.

---

## ✅ End of README

---

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

cleandb-5.0.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cleandb-5.0-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file cleandb-5.0.tar.gz.

File metadata

  • Download URL: cleandb-5.0.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for cleandb-5.0.tar.gz
Algorithm Hash digest
SHA256 0dbcd8849410fb5713f5ae546998c09c8fa6b33e00fc335d47698fc325479327
MD5 f6167c70b7a67e1f3e7368e813b9862c
BLAKE2b-256 62cc54b8f0a8a15593c515ee4b7c9639ddbdad61ced94b19d284db631e0b6406

See more details on using hashes here.

File details

Details for the file cleandb-5.0-py3-none-any.whl.

File metadata

  • Download URL: cleandb-5.0-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for cleandb-5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 240b716d7697770514e2573888a92bf176280fc14288b0685184e322cfb445cb
MD5 7656aefc3a2f30b3ab38bafc1d5b7962
BLAKE2b-256 4461850000e72bf91872d0c31282b223375bbfe6b180bdabf6bde70cfa3f14c1

See more details on using hashes here.

Supported by

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