Skip to main content

✨ Awesome databases framework that shines ✨

Version License pypi total downloads GitHub last commit

Breaking changes ⚙ 🔑 🎉 🎠 ❌

  • easy to use: lots of out-of-the-box methods.
  • less bug: not like others, I don't want to name it, and if you unluckily enough to encounter, it's easy to solve by yourself.

Installation ⚙🙈

pip install sqlstar

if you need help

sqlstar -h

Tips and tricks ✅

Guides 📝

for now, there is only mysql backend...

connection

import sqlstar

# driver://user:passwd@host:port/dbname
mysql = sqlstar.Database('mysql://root:***@localhost/tmp')
mysql.connect()

Query

QUERY = '''
    SELECT *
    FROM Girls
    WHERE AGE BETWEEN 20 AND 24
        AND BOYFRIEND IS NULL
    ORDER BY WHITE, RICH, BEAUTY DESC;
'''

Fetch data, and format result into Dataframe

df = mysql.fetch_df(QUERY)

Fetch all the rows

data = mysql.fetch_all(QUERY)

Fetch several rows

data = mysql.fetch_many(QUERY, 3)

Execute

mysql.execute("""
    CREATE TABLE `users` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `email` varchar(255) COLLATE utf8_bin NOT NULL,
        `password` varchar(255) COLLATE utf8_bin NOT NULL,
        PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
    AUTO_INCREMENT=1 ;
    """)

Insert

Insert many records

mysql.insert_many(table, data, cols)

Insert Dataframe type of data

mysql.insert_df(table, df)

Export

Export result to csv

mysql.export_csv(query, fname, sep)

Export result to excel

mysql.export_excel(query, fname)
Nice Features ✨

Create table

mysql.create_table(
    "users",
    comments={
        "name": "姓名",
        "height": "身高",
        "weight": "体重"
    },
    dtypes={
        "varchar(30)": [
            "name",
            "occupation",
        ],
        "float": ["height", "weight"],
        "int": ["age"],
    },
)

if you have data, you can make it more simple, just like this

mysql.create_table("users", df)

if you only want to specify some of them

mysql.create_table(
    table='news_spider',
    df=df,
    comments={
        "create_time": "插入时间",
        "title": "标题",
        "content": "正文",
        "author": "作者",
        "publish_time": "发布时间",
        "read_num": "阅读量",
    },
    # if type is not given, sqlstar will automatically inference
    dtypes={
        "datetime": ["create_time", "publish_time"],
        "longtext": ["content"],
        "varchar(100)": ["title", "author"],
        "decimal(10, 3)": ["read_num"]
    })

You don't need to fill in everything, and you just need to fill in comment or data type that you want to specify, then sqlstar will do the rest for you.

Rename table

mysql.rename_table(table, name)

Rename column

mysql.rename_column(table, column, name, dtype)

Add new column

mysql.add_column(table, column, dtype, comment, after)

Add comment for table

mysql.add_table_comment(table, comment)

Change column's attribute

mysql.change_column_attribute(table, column, dtype, notnull, comment)

Set primary key

mysql.add_primary_key(table, primary_key)

Truncate table's data, but keep the table structure

mysql.truncate_table(table)

Drop table

mysql.drop_table(table)

Drop column

mysql.drop_column(table, column)

Metadata

Release files for sqlstar 3.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlstar 3.2.5
File Size Uploaded
sqlstar-3.2.5.tar.gz 43.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlstar 3.2.5
File Interpreter ABI Platform
sqlstar-3.2.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 90.1 kB

Release files / sqlstar-3.2.5.tar.gz

Download URL sqlstar-3.2.5.tar.gz
Size 43.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a09f4460d7447ee1e55c87144c28aa0fb8b2a566006da9dd64084180412275e0
BLAKE2b-256 checksum
How to use checksums
d7359e60131c2c5d94785790dcfcc8c34b0adf256a1e3bb1ee590a9685a6bc94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.9

Release files / sqlstar-3.2.5-py2.py3-none-any.whl

Download URL sqlstar-3.2.5-py2.py3-none-any.whl
Size 46.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
450ffb3928b7a9483cc291be4a913c778a688e39d84a4b97f11b663842be5a7c
BLAKE2b-256 checksum
How to use checksums
b6be44c0c112bc0c46c0c9b1bf4a73efe2e7de7473b4d2271736902b4f118902
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.9

Release history Release notifications | RSS feed

This release

3.2.5 This release

2 release files

3.2.4

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.9

2 release files

3.1.8

2 release files

3.1.7

2 release files

3.1.6

2 release files

3.1.5

2 release files

3.1.4

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

3 release files

3.0.3

2 release files

3.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page