Skip to main content
Welcome, please read through this brief documentation.

All the sqldict examples below will use an sqlalchemy engine e.
Certain database engines will need certain back-end modules
which in most cases are available as packages in your *nix
distribution or as .exe installers, see INSTALLATION* below.

Lets create the engine object:

>>> from sqlalchemy import *
>>> dburi = 'mysql://user:pass@localhost/sqldict'
>>> e = create_engine(dburi)

Create database tables, t1 and t2, to hold dicts d1 and d2:

>>> d1 = sqldict(e, "t1", create=1)
>>> d2 = sqldict(e, "t2", create=1, keytype=String(50), valtype=Integer)

An sqldict() support all or most common dict operations depending on
which sqldict extensions are chosen.

This is a selection of some useful sqldict instantiation args:

echo - print all executed sql queries to stdout (bool)
create - create database table (bool)
sort - 0=no sort, 1=keys, 2=values
serialize - transparent pickling for non-String type values
assigned to String-type columns (bool)
getrow - get entire row instead of just val (bool)
keycol - name of key column
valcol - name of val column
keytype - sqlalchemy column type for key
valtype - sqlalchemy column type for val

Actions taken such as setting/getting items result in logically
corresponding SQL statements. Some examples are:

__getitem__() - SELECT keycol FROM tablename WHERE valcol=%(val)s
iter*() - iterate over result-set from a select statement
keys|values() - returns list(iter*())
__del__() - DELETE FROM..
__setitem__() - UPDATE.., INSERT..



>>> contents = {"asd":123}
>>> d1.update(contents)
>>> d2.update(contents)
>>> assert d1["asd"] == "123"
>>> assert d2["asd"] == 123
>>> d1.drop()
>>> d2.drop()

>>> assert e.execute("create table asd (i integer, s varchar(50))")
>>> assert e.execute("insert into asd values (42, 'gubbe')")
>>> assert e.execute("insert into asd values (99, 'hatt')")
>>> d3 = sqldict(e, "asd", keycol="s", valcol="i")
>>> d4 = sqldict(e, "asd", keycol="i", valcol="s")
>>> #d5 = sqldict(e, "asd", keycol="s", valgetter=lambda r:r)
>>> assert d3["gubbe"] == 42
>>> assert d4[42] == "gubbe"
>>> assert e.execute("drop table asd")
>>>
>>> #assert d5["gubbe"]["i"] == 42

broken (at least mysql) when combining keytype and serialize,
it tries to serialize 42.
FIXME: d[int] = Integer or d[Integer]
>>> from sqlalchemy import *
>>> d = sqldict(e, "laarge", create=1, serialize=1, keytype=Integer)
>>> d[42] = "galning"

INSTALLATION INSTRUCTIONS

I use debian, so I do the following:
$ sudo apt-get install python-setuptools python-mysqldb
$ easy_install sqlalchemy
$ easy_install sqldict

Metadata

Release files for sqldict 0.5.2

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

Source distribution (sdist)

Source distribution for sqldict 0.5.2
File Size Uploaded Provenance Actions
sqldict-0.5.2.tar.gz 10.2 kB Without provenance Details for sqldict-0.5.2.tar.gz

Release files / sqldict-0.5.2.tar.gz

Download URL sqldict-0.5.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
28f198855180f93cd8fca23c94aae04a4db06d4df352b09b4047f83e73ac03fa
BLAKE2b-256 checksum
How to use checksums
88ea27e37ff9fd08522c9a25f100d8a5981f5d2b00fb9599101364441aafdf85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for sqldict 0.5.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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