Coder Social home page Coder Social logo

essaalshammri / databasez Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dymmond/databasez

0.0 0.0 0.0 137 KB

Async database support for Python

Home Page: https://databasez.tarsild.io

License: MIT License

Shell 1.87% Python 97.66% Makefile 0.47%

databasez's Introduction

Databasez

databasez

๐Ÿš€ Async database support for Python. ๐Ÿš€

Test Suite Package version Supported Python versions


Documentation: https://databasez.tarsild.io ๐Ÿ“š

Source Code: https://github.com/tarsil/databasez


Motivation

There is a great package from Encode that was doing what this package was initially forked to do but Encode is also very busy with other projects and without the proper time to maintain the so much required package.

From a need to extend to new drivers and newest technologies and adding extra features common and useful to the many, Databases was forked to become Databasez.

This package is 100% backwards compatible with Databases from Encode and will remain like this for the time being but adding extra features and regular updates as well as continuing to be community driven.

By the time this project was created, Databases was yet to merge possible SQLAlchemy 2.0 changes from the author of this package and therefore, this package aims to unblock a lot of the projects out there that want SQLAlchemy 2.0 with the best of databases with new features.

A lot of packages depends of Databases and this was the main reason for the fork of Databasez. The need of progressing.

It allows you to make queries using the powerful SQLAlchemy Core expression language, and provides support for PostgreSQL, MySQL, SQLite and MSSQL.

Databasez is suitable for integrating against any async Web framework, such as Esmerald, Starlette, Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI.

Databasez was built for Python 3.8+ and on the top of the newest SQLAlchemy 2 and gives you simple asyncio support for a range of databases.

Installation

$ pip install databasez

If you are interested in using the test client, you can also install:

$ pip install databasez[testing]

What does databasez support at the moment

Databasez currently supports sqlite, postgres, mysql and sql server. More drivers can and will be added in the future.

Database drivers supported are:

Driver installation

You can install the required database drivers with:

Postgres

$ pip install databasez[asyncpg]

or

$ pip install databasez[aiopg]

MySQL/MariaDB

$ pip install databasez[aiomysql]

or

$ pip install databasez[asyncmy]

SQLite

$ pip install databasez[aiosqlite]

MSSQL

$ pip install databasez[aioodbc]

!!! Note Note that if you are using any synchronous SQLAlchemy functions such as engine.create_all() or alembic migrations then you still have to install a synchronous DB driver: psycopg2 for PostgreSQL, pymysql for MySQL and pyodbc for SQL Server.


Quickstart

For a simple quickstart example, we will be creating a simple SQLite database to run some queries against.

First, install the required drivers for SQLite and ipython. The ipython is to have an interactive python shell with some extras. IPython also supports await, which is exactly what we need. See more details about it.

Install the required drivers

$ pip install databasez[aiosqlite]
$ pip install ipython

Now from the console, we can run a simple example.

# Create a database instance, and connect to it.
from databasez import Database

database = Database("sqlite+aiosqlite:///example.db")
await database.connect()

# Create a table.
query = """CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)"""
await database.execute(query=query)

# Insert some data.
query = "INSERT INTO HighScores(name, score) VALUES (:name, :score)"
values = [
    {"name": "Daisy", "score": 92},
    {"name": "Neil", "score": 87},
    {"name": "Carol", "score": 43},
]
await database.execute_many(query=query, values=values)

# Run a database query.
query = "SELECT * FROM HighScores"
rows = await database.fetch_all(query=query)

print("High Scores:", rows)

Check out the documentation on making database queries for examples of how to start using databasez together with SQLAlchemy core expressions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.