Skip to main content

Lightweight Excel-based CRUD database using openpyxl

Project description

excel-database

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.0.tar.gz (5.5 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.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: excel_database-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 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.0.tar.gz
Algorithm Hash digest
SHA256 3d06587d59f94620f283f2c372c0c10d4aca74ab6551ad8ddaa23ae9397adb1f
MD5 e37fd5695df510b181bf6a8f7b91011a
BLAKE2b-256 56e11f535b509fdcb6062de243e319865459fec90c33141521249125bb4fa87c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: excel_database-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc25a5bec8ab7fadc09a47d11d04641c9b6497acaf0821f9a1066fe7a799a6ee
MD5 5d48abe7d4f8c75d70ced12b4bff4051
BLAKE2b-256 e0851d8992d836020508aa43289ccbab096b335c88240fa6c5878590f893b518

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