pandas-liteql


Namepandas-liteql JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://github.com/forgineer/pandas-liteql
SummaryA simple pandas extension that enables users to execute SQL statements against DataFrames using
upload_time2023-10-16 04:06:54
maintainer
docs_urlNone
authorforgineer
requires_python>=3.7
licenseMIT License
keywords dataframe pandas sql sqlite
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
    <img src="https://forgineer.pythonanywhere.com/static/pandas_liteql/pandas-liteql-logo.png" alt="pandas-liteql-logo.png"><br>
</div>

---

# What is pandas-liteql?
**pandas-liteql** is a simple [pandas](https://pandas.pydata.org/) extension that enables users to execute SQL statements against DataFrames using in-memory [SQLite](https://www.sqlite.org/index.html). It is meant to streamline data manipulation and analysis tasks. For more detailed information and examples on **pandas-liteql**, visit the [documentation pages](https://forgineer.pythonanywhere.com/pandas-liteql).

# What pandas-liteql is not
**pandas-liteql** is not a competitor to libraries such as [PySpark](https://spark.apache.org/docs/latest/api/python/index.html) or [DuckDB](https://duckdb.org/) that can perform SQL queries on larger data sets and perform more advanced data science use-cases. Rather, it is inspired by those projects and similar libraries that have performed the same function, but have since been abandoned or were not as user-friendly.

# Installing pandas-liteql
**pandas-liteql** requires a minimum of Python 3.7 and the following libraries:

| Library    | Version      |
|------------|--------------|
| Pandas     | `>= 1.3.5`   |
| SQLAlchemy | `>= 1.4.36`  |

Assuming these prerequisites are already installed, adding **pandas-liteql** is as simple as...

```
pip install pandas-liteql
```

# Examples
Below are some usage examples to load, query, and drop data from the in-memory SQLite sessions established with **pandas-liteql** and pandas DataFrame integration. For more in-depth information and examples visit the [documentation pages](https://forgineer.pythonanywhere.com/pandas-liteql).

## Loading
Start by loading your DataFrame with the `load` function. When **pandas-liteql** is imported, an in-memory SQLite session is created where data can be loaded to.

```python
import pandas as pd
import pandas_liteql as lql

# Data set creation
person_data = {
    'name': ['Bill', 'Ted', 'Abraham', 'Genghis', 'Napoleon'],
    'age': [25, 24, 56, 64, 51],
    'email': ['bill@excellent.com', 'ted@excellent.com',
              'lincoln@excellent.com', 'khan@excellent.com',
              'bonaparte@excellent.com']
}

# DataFrame creation
person_df = pd.DataFrame(data=person_data)

# Loading the DataFrame to in-memory SQLite as the 'person' table
# The 'person' variable is also a LiteQL class containing the table name and schema information
person = lql.load(df=person_df, table_name='person')

print(f'Table name: {person.name}')
print(person.schema)
```

Output:
```
Table name: person
    name    type  nullable default autoincrement  primary_key
0  index  BIGINT      True    None          auto            0
1   name    TEXT      True    None          auto            0
2    age  BIGINT      True    None          auto            0
3  email    TEXT      True    None          auto            0
```

## Querying
Next, query the table using the `query` function. Using SQL syntax, the loaded table can be queried and the results will be returned as a pandas DataFrame.

```python
bill_and_ted = lql.query(sql='SELECT * FROM person WHERE age < 30')

print(bill_and_ted)
```

Output:
```
   index  name  age               email
0      0  Bill   25  bill@excellent.com
1      1   Ted   24   ted@excellent.com
```

## Dropping
If finished with a table within the flow of a script, you can simply drop it with the `drop` function to preserve memory.

```python
lql.drop(table_name='person')
```

## The DataFrame SQL Accessor
Lastly, for a more simplistic approach, you can use the `liteql.sql` accessor to perform the same functions above in one line and return the result as a pandas DataFrame. This approach requires that you query from the `liteql` table that is loaded from the DataFrame, queried, and then dropped.

```python
import pandas as pd
import pandas_liteql as lql

# Data set creation
person_data = {
    'name': ['Bill', 'Ted', 'Abraham', 'Genghis', 'Napoleon'],
    'age': [25, 24, 56, 64, 51],
    'email': ['bill@excellent.com', 'ted@excellent.com',
              'lincoln@excellent.com', 'khan@excellent.com',
              'bonaparte@excellent.com']
}

# DataFrame creation
person_df = pd.DataFrame(data=person_data)

bill_and_ted = person_df.liteql.sql('SELECT * FROM liteql WHERE age < 30')

print(bill_and_ted)
```

Output:
```
   index  name  age               email
0      0  Bill   25  bill@excellent.com
1      1   Ted   24   ted@excellent.com
```


# Contributing
Contributions are welcome via pull request from a fork. Log issues if any bugs are found or if you have some good ideas of how this project could be expanded on. Depending on interest, other contributors could be added to meet the demand in features.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/forgineer/pandas-liteql",
    "name": "pandas-liteql",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "dataframe,pandas,sql,sqlite",
    "author": "forgineer",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/83/8d/2c0f887c44e9d38878567db2422a97320dcde9e50f88e4b44bb12e0d5657/pandas-liteql-0.5.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n    <img src=\"https://forgineer.pythonanywhere.com/static/pandas_liteql/pandas-liteql-logo.png\" alt=\"pandas-liteql-logo.png\"><br>\r\n</div>\r\n\r\n---\r\n\r\n# What is pandas-liteql?\r\n**pandas-liteql** is a simple [pandas](https://pandas.pydata.org/) extension that enables users to execute SQL statements against DataFrames using in-memory [SQLite](https://www.sqlite.org/index.html). It is meant to streamline data manipulation and analysis tasks. For more detailed information and examples on **pandas-liteql**, visit the [documentation pages](https://forgineer.pythonanywhere.com/pandas-liteql).\r\n\r\n# What pandas-liteql is not\r\n**pandas-liteql** is not a competitor to libraries such as [PySpark](https://spark.apache.org/docs/latest/api/python/index.html) or [DuckDB](https://duckdb.org/) that can perform SQL queries on larger data sets and perform more advanced data science use-cases. Rather, it is inspired by those projects and similar libraries that have performed the same function, but have since been abandoned or were not as user-friendly.\r\n\r\n# Installing pandas-liteql\r\n**pandas-liteql** requires a minimum of Python 3.7 and the following libraries:\r\n\r\n| Library    | Version      |\r\n|------------|--------------|\r\n| Pandas     | `>= 1.3.5`   |\r\n| SQLAlchemy | `>= 1.4.36`  |\r\n\r\nAssuming these prerequisites are already installed, adding **pandas-liteql** is as simple as...\r\n\r\n```\r\npip install pandas-liteql\r\n```\r\n\r\n# Examples\r\nBelow are some usage examples to load, query, and drop data from the in-memory SQLite sessions established with **pandas-liteql** and pandas DataFrame integration. For more in-depth information and examples visit the [documentation pages](https://forgineer.pythonanywhere.com/pandas-liteql).\r\n\r\n## Loading\r\nStart by loading your DataFrame with the `load` function. When **pandas-liteql** is imported, an in-memory SQLite session is created where data can be loaded to.\r\n\r\n```python\r\nimport pandas as pd\r\nimport pandas_liteql as lql\r\n\r\n# Data set creation\r\nperson_data = {\r\n    'name': ['Bill', 'Ted', 'Abraham', 'Genghis', 'Napoleon'],\r\n    'age': [25, 24, 56, 64, 51],\r\n    'email': ['bill@excellent.com', 'ted@excellent.com',\r\n              'lincoln@excellent.com', 'khan@excellent.com',\r\n              'bonaparte@excellent.com']\r\n}\r\n\r\n# DataFrame creation\r\nperson_df = pd.DataFrame(data=person_data)\r\n\r\n# Loading the DataFrame to in-memory SQLite as the 'person' table\r\n# The 'person' variable is also a LiteQL class containing the table name and schema information\r\nperson = lql.load(df=person_df, table_name='person')\r\n\r\nprint(f'Table name: {person.name}')\r\nprint(person.schema)\r\n```\r\n\r\nOutput:\r\n```\r\nTable name: person\r\n    name    type  nullable default autoincrement  primary_key\r\n0  index  BIGINT      True    None          auto            0\r\n1   name    TEXT      True    None          auto            0\r\n2    age  BIGINT      True    None          auto            0\r\n3  email    TEXT      True    None          auto            0\r\n```\r\n\r\n## Querying\r\nNext, query the table using the `query` function. Using SQL syntax, the loaded table can be queried and the results will be returned as a pandas DataFrame.\r\n\r\n```python\r\nbill_and_ted = lql.query(sql='SELECT * FROM person WHERE age < 30')\r\n\r\nprint(bill_and_ted)\r\n```\r\n\r\nOutput:\r\n```\r\n   index  name  age               email\r\n0      0  Bill   25  bill@excellent.com\r\n1      1   Ted   24   ted@excellent.com\r\n```\r\n\r\n## Dropping\r\nIf finished with a table within the flow of a script, you can simply drop it with the `drop` function to preserve memory.\r\n\r\n```python\r\nlql.drop(table_name='person')\r\n```\r\n\r\n## The DataFrame SQL Accessor\r\nLastly, for a more simplistic approach, you can use the `liteql.sql` accessor to perform the same functions above in one line and return the result as a pandas DataFrame. This approach requires that you query from the `liteql` table that is loaded from the DataFrame, queried, and then dropped.\r\n\r\n```python\r\nimport pandas as pd\r\nimport pandas_liteql as lql\r\n\r\n# Data set creation\r\nperson_data = {\r\n    'name': ['Bill', 'Ted', 'Abraham', 'Genghis', 'Napoleon'],\r\n    'age': [25, 24, 56, 64, 51],\r\n    'email': ['bill@excellent.com', 'ted@excellent.com',\r\n              'lincoln@excellent.com', 'khan@excellent.com',\r\n              'bonaparte@excellent.com']\r\n}\r\n\r\n# DataFrame creation\r\nperson_df = pd.DataFrame(data=person_data)\r\n\r\nbill_and_ted = person_df.liteql.sql('SELECT * FROM liteql WHERE age < 30')\r\n\r\nprint(bill_and_ted)\r\n```\r\n\r\nOutput:\r\n```\r\n   index  name  age               email\r\n0      0  Bill   25  bill@excellent.com\r\n1      1   Ted   24   ted@excellent.com\r\n```\r\n\r\n\r\n# Contributing\r\nContributions are welcome via pull request from a fork. Log issues if any bugs are found or if you have some good ideas of how this project could be expanded on. Depending on interest, other contributors could be added to meet the demand in features.\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A simple pandas extension that enables users to execute SQL statements against DataFrames using",
    "version": "0.5.1",
    "project_urls": {
        "Homepage": "https://github.com/forgineer/pandas-liteql"
    },
    "split_keywords": [
        "dataframe",
        "pandas",
        "sql",
        "sqlite"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "438d506cec1e2851c2d3c854ed3a3bbc26cc7ca14681efb1499ba865438ee60e",
                "md5": "12ff16afdb688c14ff224a871ba1c487",
                "sha256": "a48189cb07d6dc2e5ed9968a30bd16bb58f13c7f917da00d7b0fb4b69ef16ede"
            },
            "downloads": -1,
            "filename": "pandas_liteql-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "12ff16afdb688c14ff224a871ba1c487",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5595,
            "upload_time": "2023-10-16T04:06:53",
            "upload_time_iso_8601": "2023-10-16T04:06:53.064330Z",
            "url": "https://files.pythonhosted.org/packages/43/8d/506cec1e2851c2d3c854ed3a3bbc26cc7ca14681efb1499ba865438ee60e/pandas_liteql-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "838d2c0f887c44e9d38878567db2422a97320dcde9e50f88e4b44bb12e0d5657",
                "md5": "f03712eaa1b0f41d8b7eccab066f6fdf",
                "sha256": "6ea178277d7441469b00e98ac412b797e513f1d0e61657f682af374b78fe0564"
            },
            "downloads": -1,
            "filename": "pandas-liteql-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f03712eaa1b0f41d8b7eccab066f6fdf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5181,
            "upload_time": "2023-10-16T04:06:54",
            "upload_time_iso_8601": "2023-10-16T04:06:54.619896Z",
            "url": "https://files.pythonhosted.org/packages/83/8d/2c0f887c44e9d38878567db2422a97320dcde9e50f88e4b44bb12e0d5657/pandas-liteql-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-16 04:06:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "forgineer",
    "github_project": "pandas-liteql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pandas-liteql"
}
        
Elapsed time: 0.13157s