Skip to main content

SQLite3 Wrapper for Python

Project description

This module is meant to be used in small to medium scale applications and makes SQLite3 Read and Write functions python. Changing every DataBase, Table and Row object to classes.

Quickstart

pip install data3
  1. To get the entire DataBase use:
    import data3
    
    with data.open() as db:
      pass
    
    Alternatively, you can use the following code to get just one table:
    with data.open(table="YourTable") as table:
       pass
    
    Data3 will automatically open and close connections for you.
  2. Index a table with databaseObject["YourTable"]
  3. Read data with table.get(), you can narrow down your search by using table.get(column=value) or use table.first() to get only the first value
  4. Adding/updating/removing data works as following: table.add(column=value, column=value...), table.update(column=value)(column=value, column=value...), table.remove(column=value).
  5. By adding, finding or updating data you will be returned a rowObject which you can index with columns to find one value, you can use rowObject.pk to get just the primaryKey, it can also be converted to a Dict or you can edit your row by using rowObject["column"] = value or rowObject(column=value, column=value)

Example

import data3

with data3.open(table = "matches") as table:
    for row in table.find(): # This will loop through every row as a rowObject.
        row["started"] = True # A row object can be changed with a set architecture for a single column.
        row(started = True) # Or you can call it for multiple.
    
    table.update(5)(started = False) # Here no key is provided, data3 will search for a primaryKey column or use the first column to find "5". As the table.update function will return another function in which you can specify every column and value you want to change.

    table(id = 90, started = False) # You can call a table to add a value or use "table.add".

    print(table.first(3)["started"]) # You can get one column like this also.

    with table.pause(): # Pause will temporarily close the connection and re-open it once you're done, useful when doing large computations that don't require reading the file.
        print("Free from the database.")

    print("Back to reading and writing.")

    table.remove(3) # Here no key is provided, data3 will search for a primaryKey column or use the first column to find "3". If you do want to specify a column you can use .remove(column = value).

Edit default values

import data3

# These are the default values and you can edit them accordingly
data3.path = './'
data3.defaultFile = "data"
data3.fileExtension = ".db"
data3.defaultTimeout = 10

# This is the default onError function, which you can modify
def onError(error, cmd):
    print(f"[Error\t] {error}\n[input\t] {cmd}")
data3.onError = onError

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

data3-1.0.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

data3-1.0.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file data3-1.0.1.tar.gz.

File metadata

  • Download URL: data3-1.0.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for data3-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dd3ccbe89eaed2147f8505e180b45e61e15f451424c987137a41b8425b7f2601
MD5 0237d2848e69869c4ac5be53ccaf7590
BLAKE2b-256 a5e708a3094ff862d7b4a9b787b15b0bc484ca0fd1b09333c221e086100a10c0

See more details on using hashes here.

File details

Details for the file data3-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: data3-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for data3-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e06854269c87e0c5bff52a6255ed6e3f8ed72174eaed573bcaadf2c5e56e1d94
MD5 a531590665625f8a2d4d999f79f87c68
BLAKE2b-256 0ff7b7a256948634a0cee4d9a0397dbf2c557dcdbaeb0f331571f779b16f0ae1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page