Skip to main content

Lightweight Excel-based CRUD database using openpyxl

Project description

excel-database

pypi python

Lightweight Excel-based CRUD “database” backed by an Excel file, powered by openpyxl.

📦 Installation

pip install excel-database

🚀 Quick Start

from excel_database.database import ExcelDatabase

# Initialize with an Excel file path and sheet name
db = ExcelDatabase("./example.xlsx", sheet_name="Sheet1")

# --- Reading ---
rows = db.select({"id": 1})                   # Select all rows matching the query
single = db.get_column_value("id", 1, "name") # Get a single column value from the first matching row

# --- Writing ---
db.insert({"id": 3, "name": "Charlie", "age": 20})
db.update({"id": 2}, {"age": 26})
db.delete({"id": 3})

# --- Sheet Management ---
db.add_sheet("Archive", [{"date": "2025-04-27", "note": "backup"}])
exists = db.is_sheet_exists("Archive")        # Returns 1 if the sheet exists, otherwise None
names = db.get_all_sheet_names()

# --- Column Management ---
count = db.get_column_datas_number("age")     # Count of non-empty 'age' entries
db.add_column("email", "none@example.com")
db.remove_column("email")

📖 API Reference

ExcelDatabase(file_path: str, sheet_name: str = "Sheet1")

  • file_path: Path to the .xlsx file.
  • sheet_name: Name of the worksheet to operate on.
Method Description
select(query: dict) -> list[dict] | None Return all rows matching every key/value in query. Returns None if no rows.
get_column_value(search_col, search_val, target_col) Return the target_col value from the first row where search_col == search_val, or None.
insert(new_row: dict) -> None Append new_row to the sheet and save the file.
update(query: dict, update_data: dict) -> None Merge update_data into every row matching query and save.
delete(query: dict) -> None Delete all rows matching query and save.
add_sheet(name: str, initial_data: list[dict]) -> None Create a new sheet named name. If initial_data is provided, use its keys as headers and append rows.
is_sheet_exists(name: str) -> int | None Return 1 if the sheet exists, otherwise None.
get_all_sheet_names() -> list[str] List all sheet names in the workbook.
get_column_datas_number(col: str) -> int Count non-empty cells in column col.
add_column(name: str, default: Any) -> None Add a new column with header name, filling existing rows with default.
remove_column(name: str) -> None Remove column name from all rows and save.

🤝 Contributing

  1. Fork the repository
  2. Create a branch: git checkout -b feature/your-feature
  3. Implement your changes and add tests
  4. Open a Pull Request

📄 License

MIT License

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

excel_database-1.0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

excel_database-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file excel_database-1.0.1.tar.gz.

File metadata

  • Download URL: excel_database-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for excel_database-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d732a4ca583d219beaeddfe6c7b3e9b170192c1387cb91199d34a6e2664c624d
MD5 48fbe4a136f18b78f42ad4a42a86a012
BLAKE2b-256 29509ecdd3ddb0b0959a6f9414d0ec041030385621d74731de5e21fa8ed91972

See more details on using hashes here.

File details

Details for the file excel_database-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: excel_database-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for excel_database-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2647e566ca5d5ee10d5427450a496b33b6a1fa849e4378c947be91c45765b36
MD5 a6b1e62a89f25056b93a21ccd03bbc24
BLAKE2b-256 e9bb10f70adc9db97ed0a0c6ab02189669fe261048de20779231ccf15b9d4b58

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