Name | tonydbc JSON |
Version |
1.3.3
JSON |
| download |
home_page | None |
Summary | A high-level database connector for MariaDB |
upload_time | 2025-09-13 06:25:22 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <4.0,>=3.10 |
license | None |
keywords |
mariadb
database
connector
odbc
pandas
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# TonyDBC
Latest version: 1.3.3
Available on PyPI: https://pypi.org/project/tonydbc/
2024-01-07: [Release announcement on Medium](https://mcurrie-59915.medium.com/introducing-tonydbc-a-high-level-database-connector-for-mariadb-python-and-pandas-8600676fbf88)
Supports high-level database operations within Python. TonyDBC is short for Tony’s Database Connector, named for Maria’s lover in West Side Story.
TonyDBC uses the MariaDB/Connector but adds these features:
* Support for the object-oriented context manager design pattern, which automatically closes connections.
* A way to convert between pandas DataFrames and MariaDB tables, including serialization of complex data types like dictionaries and numpy arrays.
* A way to autoresume when the connection is lost.
* Support for fast INSERT and UPDATE from DataFrame.to_sql. Currently pandas’ implemention using sqlalchemy is 300x slower.
* A way to quickly and automatically clone a database from a DDL script and copy the contents from the production database.
* Batch INSERT and UPDATE offline and resume when Internet is available.
* Logging database actions using the standard logging module.
* In a CI/CD context, automatically connecting to the correct production or test database.
* Support for the np.Int64Dtype data type.
* Support for pandas timestamps.
* Able to bulk insert data containing NULLs
### Installation
To install TonyDBC from PyPI on Windows:
```bash
pip install tonydbc
```
To install TonyDBC on Ubuntu or Debian, first the MariaDB Connector / C must be installed, then the MariaDB Connector / Python must be installed, because neither can be installed via `pip3`:
```bash
cd ~
sudo apt-get install -y wget curl python3-packaging gcc
# Install mariadb CS Package Repository so apt-get can find the right package
# See https://mariadb.com/docs/skysql/connect/programming-languages/c/install/#Installation_via_Package_Repository_(Linux)
wget https://r.mariadb.com/downloads/mariadb_repo_setup || wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo ./mariadb_repo_setup --mariadb-server-version="mariadb-11.1.5"
sudo apt-get install -y libmariadb3 libmariadb-dev
pip3 install tonydbc
```
### Usage
A typical use case:
```python
from tonydbc import TonyDBC, load_dotenvs
import pandas as pd
load_dotenvs()
sql_params = {
"host": os.environ["MYSQL_HOST"],
"user": os.environ["MYSQL_USER"],
"password": os.environ["MYSQL_PASSWORD"],
"database": os.environ["MYSQL_DATABASE"],
"port": int(os.environ["MYSQL_PORT"]),
}
with TonyDBC(**sql_params) as db:
# Do stuff
contoso_users_df = db.query_table("user", f"""
SELECT *
FROM `user`
WHERE
`user`.`company` = 'Contoso'
LIMIT 10;
""")
print(contoso_users_df.first_name)
```
## Timezone Handling in TonyDBC
Internally, MariaDB stores timestamps in UTC and its insert and select return timestamps in the session timezone for that database connection session.
`db = TonyDBC()` follows the same convention as MariaDB, and tracks timezone as `db.session_timezone`.
This `db.session_timezone` is set initially by:
1. In the `db = TonyDBC(session_timezone="Asia/Bangkok")` initializer via the parameter `session_timezone`, which defaults to None.
2. If None is specified, it will be taken from the `DEFAULT_TIMEZONE` environment variable; e.g. `DEFAULT_TIMEZONE=Asia/Bangkok`.
Note: If NEITHER of the above is specified, an AssertionError will be raised during initialization.
3. Later, you can call `db.set_timezone("Asia/Bangkok")` to set the timezone to something else.
As with MariaDB commands, all insert and select statements in TonyDBC will return timestamps in the session timezone.
''Note that TonyDBC will warn if the session timezone is not the same as the system timezone.''
Raw data
{
"_id": null,
"home_page": null,
"name": "tonydbc",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "mariadb, database, connector, ODBC, pandas",
"author": null,
"author_email": "Michael Currie <mcurrie@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/dc/09/2c752065ac5ea4bd93a9de45f7a35e2b2be3c59cd858f97b946a227bd8cf/tonydbc-1.3.3.tar.gz",
"platform": null,
"description": "# TonyDBC\r\n\r\nLatest version: 1.3.3\r\n\r\nAvailable on PyPI: https://pypi.org/project/tonydbc/\r\n\r\n2024-01-07: [Release announcement on Medium](https://mcurrie-59915.medium.com/introducing-tonydbc-a-high-level-database-connector-for-mariadb-python-and-pandas-8600676fbf88)\r\n\r\nSupports high-level database operations within Python. TonyDBC is short for Tony\u2019s Database Connector, named for Maria\u2019s lover in West Side Story.\r\n\r\nTonyDBC uses the MariaDB/Connector but adds these features:\r\n\r\n* Support for the object-oriented context manager design pattern, which automatically closes connections.\r\n* A way to convert between pandas DataFrames and MariaDB tables, including serialization of complex data types like dictionaries and numpy arrays.\r\n* A way to autoresume when the connection is lost.\r\n* Support for fast INSERT and UPDATE from DataFrame.to_sql. Currently pandas\u2019 implemention using sqlalchemy is 300x slower.\r\n* A way to quickly and automatically clone a database from a DDL script and copy the contents from the production database.\r\n* Batch INSERT and UPDATE offline and resume when Internet is available.\r\n* Logging database actions using the standard logging module.\r\n* In a CI/CD context, automatically connecting to the correct production or test database.\r\n* Support for the np.Int64Dtype data type.\r\n* Support for pandas timestamps.\r\n* Able to bulk insert data containing NULLs\r\n\r\n### Installation\r\n\r\nTo install TonyDBC from PyPI on Windows:\r\n\r\n```bash\r\npip install tonydbc\r\n```\r\n\r\nTo install TonyDBC on Ubuntu or Debian, first the MariaDB Connector / C must be installed, then the MariaDB Connector / Python must be installed, because neither can be installed via `pip3`:\r\n\r\n```bash\r\ncd ~\r\n\r\nsudo apt-get install -y wget curl python3-packaging gcc\r\n\r\n# Install mariadb CS Package Repository so apt-get can find the right package\r\n# See https://mariadb.com/docs/skysql/connect/programming-languages/c/install/#Installation_via_Package_Repository_(Linux)\r\nwget https://r.mariadb.com/downloads/mariadb_repo_setup || wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup\r\nchmod +x mariadb_repo_setup\r\nsudo ./mariadb_repo_setup --mariadb-server-version=\"mariadb-11.1.5\"\r\nsudo apt-get install -y libmariadb3 libmariadb-dev\r\n\r\npip3 install tonydbc\r\n```\r\n\r\n### Usage\r\n\r\nA typical use case:\r\n\r\n```python\r\nfrom tonydbc import TonyDBC, load_dotenvs\r\nimport pandas as pd\r\n\r\nload_dotenvs()\r\n\r\nsql_params = {\r\n \"host\": os.environ[\"MYSQL_HOST\"],\r\n \"user\": os.environ[\"MYSQL_USER\"],\r\n \"password\": os.environ[\"MYSQL_PASSWORD\"],\r\n \"database\": os.environ[\"MYSQL_DATABASE\"],\r\n \"port\": int(os.environ[\"MYSQL_PORT\"]),\r\n}\r\n\r\nwith TonyDBC(**sql_params) as db:\r\n # Do stuff\r\n contoso_users_df = db.query_table(\"user\", f\"\"\"\r\n SELECT *\r\n FROM `user`\r\n WHERE\r\n `user`.`company` = 'Contoso'\r\n LIMIT 10;\r\n \"\"\")\r\n\r\n print(contoso_users_df.first_name)\r\n```\r\n\r\n## Timezone Handling in TonyDBC\r\n\r\nInternally, MariaDB stores timestamps in UTC and its insert and select return timestamps in the session timezone for that database connection session.\r\n\r\n`db = TonyDBC()` follows the same convention as MariaDB, and tracks timezone as `db.session_timezone`.\r\n\r\nThis `db.session_timezone` is set initially by:\r\n\r\n1. In the `db = TonyDBC(session_timezone=\"Asia/Bangkok\")` initializer via the parameter `session_timezone`, which defaults to None.\r\n2. If None is specified, it will be taken from the `DEFAULT_TIMEZONE` environment variable; e.g. `DEFAULT_TIMEZONE=Asia/Bangkok`.\r\n\r\nNote: If NEITHER of the above is specified, an AssertionError will be raised during initialization.\r\n\r\n3. Later, you can call `db.set_timezone(\"Asia/Bangkok\")` to set the timezone to something else.\r\n\r\nAs with MariaDB commands, all insert and select statements in TonyDBC will return timestamps in the session timezone.\r\n\r\n''Note that TonyDBC will warn if the session timezone is not the same as the system timezone.''\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A high-level database connector for MariaDB",
"version": "1.3.3",
"project_urls": {
"Homepage": "https://github.com/Fling-Asia/tonydbc"
},
"split_keywords": [
"mariadb",
" database",
" connector",
" odbc",
" pandas"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "965028f77c15278d07455cfa67ef94d725d1df95baf0721e03ce9ba0f06c5eae",
"md5": "111a7eaf00abb17296fe5ad01f32b82f",
"sha256": "dfaefd47fbb931ff939e6c380e3f91b2b6b17ac4d71ab8a17bcf7376b6f530f7"
},
"downloads": -1,
"filename": "tonydbc-1.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "111a7eaf00abb17296fe5ad01f32b82f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 41127,
"upload_time": "2025-09-13T06:25:20",
"upload_time_iso_8601": "2025-09-13T06:25:20.246833Z",
"url": "https://files.pythonhosted.org/packages/96/50/28f77c15278d07455cfa67ef94d725d1df95baf0721e03ce9ba0f06c5eae/tonydbc-1.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dc092c752065ac5ea4bd93a9de45f7a35e2b2be3c59cd858f97b946a227bd8cf",
"md5": "dc42fe6e88b13bcfa563ad08a951493d",
"sha256": "f6f92ebbfce4bb6d6d5b43f37b64dcb8caade642e86185ae4cefa1b53641b6df"
},
"downloads": -1,
"filename": "tonydbc-1.3.3.tar.gz",
"has_sig": false,
"md5_digest": "dc42fe6e88b13bcfa563ad08a951493d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 56850,
"upload_time": "2025-09-13T06:25:22",
"upload_time_iso_8601": "2025-09-13T06:25:22.155214Z",
"url": "https://files.pythonhosted.org/packages/dc/09/2c752065ac5ea4bd93a9de45f7a35e2b2be3c59cd858f97b946a227bd8cf/tonydbc-1.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-13 06:25:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Fling-Asia",
"github_project": "tonydbc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tonydbc"
}