Skip to main content

sqldict - You have a dict with transparent object serialization and unlimited capacity, it's up to you now.

Project description

sqldict - dict with sqlalchemy database-agnostic back-end

interface cleanup, numerous bugs fixed, and LOTS of testing added. You can now create a dict out of arbitrary key/value columns of any existing database table, in addition to ordinary dedicated strict or auto-pickling sqldicts.

Basic use:

>>> from sqldict import sqldict
>>> from sqlalchemy import *
>>> #d0 = sqldict("mysql://user:pass@dbhost/dbname", "table0", create=1)
>>> engine = create_engine("sqlite://")
>>> d1 = sqldict(engine, "table1", create=1)
>>> d2 = sqldict(engine, "table2", create=1, valtype=Integer)
>>> contents = {"asd":123}
>>> d1.update(contents)
>>> d2.update(contents)
>>> assert d1["asd"] == "123"
>>> assert d2["asd"] == 123

Make dict from existing database table:

>>> _ = engine.execute("create table asd (i integer, s varchar(50))")
>>> _ = engine.execute("insert into asd values (42, 'gubbe')")
>>> d3 = sqldict(engine, "asd", keycol="s", valcol="i")
>>> d4 = sqldict(engine, "asd", keycol="i", valcol="s")
>>> assert d3["gubbe"] == 42
>>> assert d4[42] == "gubbe"

Key-val serializing and only val serializing sqldicts; a’s key column type is String, b’s key column type is Integer. The obvious use case for b is HUGE dicts where only integer indexes are allowed:

>>> a = sqldict(engine, "serty1", create=1, serialize=1)
>>> b = sqldict(engine, "serty2", create=1, serialize=1, keytype=Integer)
>>>
>>> a[1] = (2,3)
>>> assert a[1] == (2,3)
>>> b[4] = (5,6)
>>> assert b[4] == (5,6)

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

sqldict-0.5.0.tar.gz (8.6 kB view details)

Uploaded Source

File details

Details for the file sqldict-0.5.0.tar.gz.

File metadata

  • Download URL: sqldict-0.5.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sqldict-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ab729c345ac4e40852c5b4727e670cdf262a499ea36ddc8b3dcee8368177bf72
MD5 1bf40875c22f6b797b93ab1f826ed57a
BLAKE2b-256 106d48ef758c012e8e9fc7b26181161f2cfeced3eb4402506a4057004d32645e

See more details on using hashes here.

Supported by

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