pandas-liteql


Namepandas-liteql JSON
Version 0.5.3 PyPI version JSON
download
home_pageNone
SummaryA simple pandas extension that enables users to execute SQL statements against DataFrames using in-memory SQLite.
upload_time2024-05-20 04:57:05
maintainerNone
docs_urlNone
authorNone
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-feather-logo-large.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.

## 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
from src 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
Currently, **pandas-liteql** will not be receiving any additional updates. Contributions will not be accepted here, but feel free to fork this project if you desire.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pandas-liteql",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "dataframe, pandas, sql, sqlite",
    "author": null,
    "author_email": "forgineer <blake.phillips86@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/cc/82/6f70f8924011b869d0531dcaed7ea3732fa76527f19ceb44cef05565face/pandas_liteql-0.5.3.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n    <img src=\"https://forgineer.pythonanywhere.com/static/pandas_liteql/pandas-liteql-feather-logo-large.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.\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\nfrom src import 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\nCurrently, **pandas-liteql** will not be receiving any additional updates. Contributions will not be accepted here, but feel free to fork this project if you desire.\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A simple pandas extension that enables users to execute SQL statements against DataFrames using in-memory SQLite.",
    "version": "0.5.3",
    "project_urls": {
        "Documentation": "https://github.com/forgineer/pandas-liteql",
        "Homepage": "https://github.com/forgineer/pandas-liteql",
        "Issues": "https://github.com/forgineer/pandas-liteql/issues",
        "Repository": "https://github.com/forgineer/pandas-liteql"
    },
    "split_keywords": [
        "dataframe",
        " pandas",
        " sql",
        " sqlite"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d544e3ce82309670518e77de17a4caae2f429776b7b4814d98d5ed508fbde134",
                "md5": "b35821c0a00edb5a4f464f0d341c05ea",
                "sha256": "84154c73a2a749437edb96529992e9d02239b59b72a9d393f8bfbd0b3cb60690"
            },
            "downloads": -1,
            "filename": "pandas_liteql-0.5.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b35821c0a00edb5a4f464f0d341c05ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5710,
            "upload_time": "2024-05-20T04:57:04",
            "upload_time_iso_8601": "2024-05-20T04:57:04.122376Z",
            "url": "https://files.pythonhosted.org/packages/d5/44/e3ce82309670518e77de17a4caae2f429776b7b4814d98d5ed508fbde134/pandas_liteql-0.5.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc826f70f8924011b869d0531dcaed7ea3732fa76527f19ceb44cef05565face",
                "md5": "139cfbe2e84db5cf4f5ca40dfe411f14",
                "sha256": "a7ef84dcf13ce07b483bcfdca0675a47925bd4762a69bff2e03b60ffd52bf345"
            },
            "downloads": -1,
            "filename": "pandas_liteql-0.5.3.tar.gz",
            "has_sig": false,
            "md5_digest": "139cfbe2e84db5cf4f5ca40dfe411f14",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5955,
            "upload_time": "2024-05-20T04:57:05",
            "upload_time_iso_8601": "2024-05-20T04:57:05.691465Z",
            "url": "https://files.pythonhosted.org/packages/cc/82/6f70f8924011b869d0531dcaed7ea3732fa76527f19ceb44cef05565face/pandas_liteql-0.5.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-20 04:57:05",
    "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: 8.92755s