parquetdb


Nameparquetdb JSON
Version 0.5.11 PyPI version JSON
download
home_pageNone
SummaryParquetDB is a lightweight database-like system built on top of Apache Parquet files using PyArrow.
upload_time2024-10-25 05:38:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2023 lllangWV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords parquet pyarrow data storage schema evolution nested and complex data types scalable database python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ParquetDB

ParquetDB is a lightweight database-like system built on top of Apache Parquet files using PyArrow. It offers a simple and efficient way to store, manage, and retrieve complex data types without the overhead of serialization, which is often a bottleneck in machine learning pipelines. By leveraging Parquet's columnar storage format and PyArrow's computational capabilities, ParquetDB provides high performance for data-intensive applications. 


![Benchmark Create and Read Times for Different Databases](benchmarks/benchmark_create_read_times.png)

## Table of Contents

- [Features](#features)
- [Why ParquetDB?](#why-parquetdb)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
  - [Creating a Database](#creating-a-database)
  - [Adding Data](#adding-data)
  - [Reading Data](#reading-data)
  - [Updating Data](#updating-data)
  - [Deleting Data](#deleting-data)
- [Benchmark Overview](#benchmark-overview)
- [Contributing](#contributing)
- [License](#license)

## Features

- **Simple Interface**: Easy-to-use methods for creating, reading, updating, and deleting data.
- **High Performance**: Utilizes Apache Parquet and PyArrow for efficient data storage and retrieval.
- **Supports Complex Data Types**: Handles nested and complex data types without serialization overhead.
- **Scalable**: Designed to handle large datasets efficiently.
- **Schema Evolution**: Supports adding new fields and updating schemas seamlessly.

## Roadmap

- Support foriegn keys use
- Multiprocessing for reading and writing

## Why ParquetDB?

### The Challenge of Serialization and Deserialization

In many data processing and machine learning workflows, a significant performance bottleneck occurs during the serialization and deserialization of data. Serialization is the process of converting complex data structures or objects into a format that can be easily stored or transmitted, while deserialization is the reverse process of reconstructing these objects from the serialized format.

The need for serialization arises when:
1. Storing data on disk
2. Transmitting data over a network
3. Caching data in memory

However, serialization and deserialization can be computationally expensive, especially when dealing with large datasets or complex object structures. This process can lead to:

- Increased I/O operations
- Higher CPU usage
- Increased memory consumption
- Longer processing times

These issues become particularly problematic in machine learning pipelines, where data needs to be frequently loaded, processed, and saved. The overhead of constantly serializing and deserializing data can significantly slow down the entire workflow, affecting both development iteration speed and production performance.

### How Parquet Files Address the Serialization Challenge

Apache Parquet files offer a solution to the serialization/deserialization problem by providing:

1. **Columnar Storage Format**: Parquet stores data in a columnar format, which allows for efficient compression and encoding schemes. This format is particularly beneficial for analytical queries that typically involve a subset of columns.
2. **Schema Preservation**: Parquet files store the schema of the data along with the data itself. This eliminates the need for separate schema definitions and reduces the risk of schema mismatch errors.
3. **Efficient Encoding**: Parquet uses advanced encoding techniques like dictionary encoding, bit packing, and run length encoding, which can significantly reduce file sizes and improve read performance.
4. **Predicate Pushdown**: Parquet supports predicate pushdown, allowing queries to skip irrelevant data blocks entirely, further improving query performance.
5. **Compatibility**: Parquet files are compatible with various big data processing frameworks, making it easier to integrate into existing data pipelines.

By leveraging these features, ParquetDB eliminates the need for explicit serialization and deserialization of complex data types. Data can be read directly from and written directly to Parquet files, maintaining its structure and allowing for efficient querying and processing.

### The ParquetDB Advantage

ParquetDB builds upon the benefits of Parquet files by providing:

1. A simple, database-like interface for working with Parquet files
2. Efficient storage and retrieval of complex data types
3. High-performance data operations leveraging PyArrow's computational capabilities
4. Seamless integration with machine learning pipelines and data processing workflows

By using ParquetDB, developers and data scientists can focus on their core tasks without worrying about the intricacies of data serialization or the performance implications of frequent I/O operations. This results in faster development cycles, improved system performance, and more efficient use of computational resources.


## Installation

Install ParquetDB using pip:

```bash
pip install parquetdb
```

## Quick Start

```python
from parquetdb import ParquetDB

# Initialize the database
db = ParquetDB(dataset_name='parquetdb')

# Create data
data = [
    {'name': 'Alice', 'age': 30, 'occupation': 'Engineer'},
    {'name': 'Bob', 'age': 25, 'occupation': 'Data Scientist'}
]

# Add data to the database
db.create(data)

# Read data from the database
employees = db.read()
print(employees.to_pandas())
```

## Usage

### Creating a Database

Initialize a ParquetDB instance by specifying the path the name of the dataset

```python
from parquetdb import ParquetDB

db = ParquetDB(dataset_name='parquetdb')
```

### Adding Data

Add data to the database using the `create` method. Data can be a dictionary, a list of dictionaries, or a Pandas DataFrame.

```python
data = [
    {'name': 'Charlie', 'age': 28, 'occupation': 'Designer'},
    {'name': 'Diana', 'age': 32, 'occupation': 'Product Manager'}
]

db.create(data)
```

### Normalizing

Normalization is a crucial process for ensuring the optimal performance and efficient management of data. In the context of file-based databases, like the ones used in ParquetDB, normalization helps balance the distribution of data across multiple files. Without proper normalization, files can end up with uneven row counts, leading to performance bottlenecks during operations like queries, inserts, updates, or deletions.

This method does not return anything but modifies the dataset directory in place, ensuring a more consistent and efficient structure for future operations.

```python
db.normalize(
    normalize_config=NormalizeConfig(
    load_format='batches',      # Uses the batch generator to normalize
    batch_readahead=10,         # Controls the number of batches to load in memory a head of time.
    fragment_readahead=2,       # Controls the number of files to load in memory ahead of time.
    batch_size = 100000,        # Controls the batchsize when to use when normalizing. This will have impacts on amount of RAM consumed
    max_rows_per_file=500000,   # Controls the max number of rows per parquet file
    max_rows_per_group=500000)  # Controls the max number of rows per group parquet file
)
```

### Reading Data

Read data from the database using the `read` method. You can filter data by IDs, specify columns, and apply filters.

```python
# Read all data
all_employees = db.read()

# Read specific columns
names = db.read( columns=['name'])

# Read data with filters
from pyarrow import compute as pc

age_filter = pc.field('age') > 30
older_employees = db.read(filters=[age_filter])
```

### Updating Data

Update existing records in the database using the `update` method. Each record must include the `id` field.

```python
update_data = [
    {'id': 1, 'occupation': 'Senior Engineer'},
    {'id': 3, 'age': 29}
]

db.update(update_data)
```

### Deleting Data

Delete records from the database by specifying their IDs.

```python
db.delete(ids=[2, 4])
```


## Benchmark Overview

A benchmark was conducted to evaluate the performance of ParquetDB, SQLite, and MongoDB. The benchmark measures the read and write times for datasets consisting of 100 integer columns across varying record sizes.

#### Write Performance
For write operations, we tested the time required to insert records into each database and close the connections. Bulk inserts were used for SQLite and MongoDB, but only serial inserts were tested. Specifically for SQLite, `PRAGMA synchronous = OFF` and `PRAGMA journal_mode = MEMORY` were applied to optimize write performance.

#### Read Performance
For read operations, we measured the time taken to load the entire dataset into an array-like structure. Leaving the data in a cursor was not counted as a completed read.

#### Test Environment
The benchmark was executed on the following system:
- **Processor**: AMD Ryzen 7 3700X 8-Core, 3600 MHz
- **Logical Processors**: 16
- **Memory**: 32 GB RAM

The scripts used to generate these benchmark results can be found in the `benchmarks` directory.

### Results Summary
- **Read Times**: ParquetDB is the fastest for large datasets, followed by SQLite, with MongoDB trailing.
- **Write Times**: For large datasets, SQLite achieves the fastest write times, followed by ParquetDB and MongoDB.


## Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

---

*Note: This project is in its initial stages. Features and APIs are subject to change. Please refer to the latest documentation and release notes for updates.*

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "parquetdb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "parquet, pyarrow, data, storage, schema evolution, nested and complex data types, scalable, database, python",
    "author": null,
    "author_email": "Logan Lang <lllang@mix.wvu.edu>",
    "download_url": "https://files.pythonhosted.org/packages/b3/c3/1b531c7b92c8fabca33020e8782a2d6ab2d5b90f3fe16cdb30624bb6c458/parquetdb-0.5.11.tar.gz",
    "platform": null,
    "description": "# ParquetDB\n\nParquetDB is a lightweight database-like system built on top of Apache Parquet files using PyArrow. It offers a simple and efficient way to store, manage, and retrieve complex data types without the overhead of serialization, which is often a bottleneck in machine learning pipelines. By leveraging Parquet's columnar storage format and PyArrow's computational capabilities, ParquetDB provides high performance for data-intensive applications. \n\n\n![Benchmark Create and Read Times for Different Databases](benchmarks/benchmark_create_read_times.png)\n\n## Table of Contents\n\n- [Features](#features)\n- [Why ParquetDB?](#why-parquetdb)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Usage](#usage)\n  - [Creating a Database](#creating-a-database)\n  - [Adding Data](#adding-data)\n  - [Reading Data](#reading-data)\n  - [Updating Data](#updating-data)\n  - [Deleting Data](#deleting-data)\n- [Benchmark Overview](#benchmark-overview)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- **Simple Interface**: Easy-to-use methods for creating, reading, updating, and deleting data.\n- **High Performance**: Utilizes Apache Parquet and PyArrow for efficient data storage and retrieval.\n- **Supports Complex Data Types**: Handles nested and complex data types without serialization overhead.\n- **Scalable**: Designed to handle large datasets efficiently.\n- **Schema Evolution**: Supports adding new fields and updating schemas seamlessly.\n\n## Roadmap\n\n- Support foriegn keys use\n- Multiprocessing for reading and writing\n\n## Why ParquetDB?\n\n### The Challenge of Serialization and Deserialization\n\nIn many data processing and machine learning workflows, a significant performance bottleneck occurs during the serialization and deserialization of data. Serialization is the process of converting complex data structures or objects into a format that can be easily stored or transmitted, while deserialization is the reverse process of reconstructing these objects from the serialized format.\n\nThe need for serialization arises when:\n1. Storing data on disk\n2. Transmitting data over a network\n3. Caching data in memory\n\nHowever, serialization and deserialization can be computationally expensive, especially when dealing with large datasets or complex object structures. This process can lead to:\n\n- Increased I/O operations\n- Higher CPU usage\n- Increased memory consumption\n- Longer processing times\n\nThese issues become particularly problematic in machine learning pipelines, where data needs to be frequently loaded, processed, and saved. The overhead of constantly serializing and deserializing data can significantly slow down the entire workflow, affecting both development iteration speed and production performance.\n\n### How Parquet Files Address the Serialization Challenge\n\nApache Parquet files offer a solution to the serialization/deserialization problem by providing:\n\n1. **Columnar Storage Format**: Parquet stores data in a columnar format, which allows for efficient compression and encoding schemes. This format is particularly beneficial for analytical queries that typically involve a subset of columns.\n2. **Schema Preservation**: Parquet files store the schema of the data along with the data itself. This eliminates the need for separate schema definitions and reduces the risk of schema mismatch errors.\n3. **Efficient Encoding**: Parquet uses advanced encoding techniques like dictionary encoding, bit packing, and run length encoding, which can significantly reduce file sizes and improve read performance.\n4. **Predicate Pushdown**: Parquet supports predicate pushdown, allowing queries to skip irrelevant data blocks entirely, further improving query performance.\n5. **Compatibility**: Parquet files are compatible with various big data processing frameworks, making it easier to integrate into existing data pipelines.\n\nBy leveraging these features, ParquetDB eliminates the need for explicit serialization and deserialization of complex data types. Data can be read directly from and written directly to Parquet files, maintaining its structure and allowing for efficient querying and processing.\n\n### The ParquetDB Advantage\n\nParquetDB builds upon the benefits of Parquet files by providing:\n\n1. A simple, database-like interface for working with Parquet files\n2. Efficient storage and retrieval of complex data types\n3. High-performance data operations leveraging PyArrow's computational capabilities\n4. Seamless integration with machine learning pipelines and data processing workflows\n\nBy using ParquetDB, developers and data scientists can focus on their core tasks without worrying about the intricacies of data serialization or the performance implications of frequent I/O operations. This results in faster development cycles, improved system performance, and more efficient use of computational resources.\n\n\n## Installation\n\nInstall ParquetDB using pip:\n\n```bash\npip install parquetdb\n```\n\n## Quick Start\n\n```python\nfrom parquetdb import ParquetDB\n\n# Initialize the database\ndb = ParquetDB(dataset_name='parquetdb')\n\n# Create data\ndata = [\n    {'name': 'Alice', 'age': 30, 'occupation': 'Engineer'},\n    {'name': 'Bob', 'age': 25, 'occupation': 'Data Scientist'}\n]\n\n# Add data to the database\ndb.create(data)\n\n# Read data from the database\nemployees = db.read()\nprint(employees.to_pandas())\n```\n\n## Usage\n\n### Creating a Database\n\nInitialize a ParquetDB instance by specifying the path the name of the dataset\n\n```python\nfrom parquetdb import ParquetDB\n\ndb = ParquetDB(dataset_name='parquetdb')\n```\n\n### Adding Data\n\nAdd data to the database using the `create` method. Data can be a dictionary, a list of dictionaries, or a Pandas DataFrame.\n\n```python\ndata = [\n    {'name': 'Charlie', 'age': 28, 'occupation': 'Designer'},\n    {'name': 'Diana', 'age': 32, 'occupation': 'Product Manager'}\n]\n\ndb.create(data)\n```\n\n### Normalizing\n\nNormalization is a crucial process for ensuring the optimal performance and efficient management of data. In the context of file-based databases, like the ones used in ParquetDB, normalization helps balance the distribution of data across multiple files. Without proper normalization, files can end up with uneven row counts, leading to performance bottlenecks during operations like queries, inserts, updates, or deletions.\n\nThis method does not return anything but modifies the dataset directory in place, ensuring a more consistent and efficient structure for future operations.\n\n```python\ndb.normalize(\n    normalize_config=NormalizeConfig(\n    load_format='batches',      # Uses the batch generator to normalize\n    batch_readahead=10,         # Controls the number of batches to load in memory a head of time.\n    fragment_readahead=2,       # Controls the number of files to load in memory ahead of time.\n    batch_size = 100000,        # Controls the batchsize when to use when normalizing. This will have impacts on amount of RAM consumed\n    max_rows_per_file=500000,   # Controls the max number of rows per parquet file\n    max_rows_per_group=500000)  # Controls the max number of rows per group parquet file\n)\n```\n\n### Reading Data\n\nRead data from the database using the `read` method. You can filter data by IDs, specify columns, and apply filters.\n\n```python\n# Read all data\nall_employees = db.read()\n\n# Read specific columns\nnames = db.read( columns=['name'])\n\n# Read data with filters\nfrom pyarrow import compute as pc\n\nage_filter = pc.field('age') > 30\nolder_employees = db.read(filters=[age_filter])\n```\n\n### Updating Data\n\nUpdate existing records in the database using the `update` method. Each record must include the `id` field.\n\n```python\nupdate_data = [\n    {'id': 1, 'occupation': 'Senior Engineer'},\n    {'id': 3, 'age': 29}\n]\n\ndb.update(update_data)\n```\n\n### Deleting Data\n\nDelete records from the database by specifying their IDs.\n\n```python\ndb.delete(ids=[2, 4])\n```\n\n\n## Benchmark Overview\n\nA benchmark was conducted to evaluate the performance of ParquetDB, SQLite, and MongoDB. The benchmark measures the read and write times for datasets consisting of 100 integer columns across varying record sizes.\n\n#### Write Performance\nFor write operations, we tested the time required to insert records into each database and close the connections. Bulk inserts were used for SQLite and MongoDB, but only serial inserts were tested. Specifically for SQLite, `PRAGMA synchronous = OFF` and `PRAGMA journal_mode = MEMORY` were applied to optimize write performance.\n\n#### Read Performance\nFor read operations, we measured the time taken to load the entire dataset into an array-like structure. Leaving the data in a cursor was not counted as a completed read.\n\n#### Test Environment\nThe benchmark was executed on the following system:\n- **Processor**: AMD Ryzen 7 3700X 8-Core, 3600 MHz\n- **Logical Processors**: 16\n- **Memory**: 32 GB RAM\n\nThe scripts used to generate these benchmark results can be found in the `benchmarks` directory.\n\n### Results Summary\n- **Read Times**: ParquetDB is the fastest for large datasets, followed by SQLite, with MongoDB trailing.\n- **Write Times**: For large datasets, SQLite achieves the fastest write times, followed by ParquetDB and MongoDB.\n\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n*Note: This project is in its initial stages. Features and APIs are subject to change. Please refer to the latest documentation and release notes for updates.*\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 lllangWV  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "ParquetDB is a lightweight database-like system built on top of Apache Parquet files using PyArrow.",
    "version": "0.5.11",
    "project_urls": {
        "Changelog": "https://github.com/romerogroup/ParquetDB/CHANGELOG.md",
        "Issues": "https://github.com/romerogroup/ParquetDB/issues",
        "Repository": "https://github.com/romerogroup/ParquetDB"
    },
    "split_keywords": [
        "parquet",
        " pyarrow",
        " data",
        " storage",
        " schema evolution",
        " nested and complex data types",
        " scalable",
        " database",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c65fbc54b86f14ee893849ea6758e7d1aca244d88163fdfe091007d57e3456ea",
                "md5": "21c2c29b69cd6d8428eef491be72176a",
                "sha256": "5875213a4834db8b1387faecbf32cb502d8ff9389bb7154deaf9bea9ceb3b244"
            },
            "downloads": -1,
            "filename": "parquetdb-0.5.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "21c2c29b69cd6d8428eef491be72176a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 35618,
            "upload_time": "2024-10-25T05:38:35",
            "upload_time_iso_8601": "2024-10-25T05:38:35.035072Z",
            "url": "https://files.pythonhosted.org/packages/c6/5f/bc54b86f14ee893849ea6758e7d1aca244d88163fdfe091007d57e3456ea/parquetdb-0.5.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3c31b531c7b92c8fabca33020e8782a2d6ab2d5b90f3fe16cdb30624bb6c458",
                "md5": "003eaa312c06d5fc67eeb6613944129b",
                "sha256": "7744b84d98018aae352cbf48e14c3e7f8c3437406a2894bd97af9d97ded4c035"
            },
            "downloads": -1,
            "filename": "parquetdb-0.5.11.tar.gz",
            "has_sig": false,
            "md5_digest": "003eaa312c06d5fc67eeb6613944129b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 181679,
            "upload_time": "2024-10-25T05:38:36",
            "upload_time_iso_8601": "2024-10-25T05:38:36.602723Z",
            "url": "https://files.pythonhosted.org/packages/b3/c3/1b531c7b92c8fabca33020e8782a2d6ab2d5b90f3fe16cdb30624bb6c458/parquetdb-0.5.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-25 05:38:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "romerogroup",
    "github_project": "ParquetDB",
    "github_not_found": true,
    "lcname": "parquetdb"
}
        
Elapsed time: 0.48331s