sqlitent provides a set-like interface on top of SQLite. Values can be None, int, float, str, and bytes. Tuple types are distinguished by name (case sensitive!) and number of fields. Documentation.
sqlitent was inspired by sqlitedict and kv.
Example
>>> from collections import namedtuple
>>> from sqlitent import sqlitent, fuzzy
>>> db = sqlitent('database.sqlite', autocommit=True)
>>>
>>> Point = namedtuple('Point', ['x', 'y'])
>>> p1 = Point(11, y=22)
>>> p1
Point(x=11, y=22)
>>> p2 = p._replace(x=33)
Point(x=33, y=22)
>>> Car = namedtuple('Car', [
... 'brand',
... 'model',
... 'configuration',
... 'hp',
... ])
>>> c = Car('Audi', 'A1', 'Sport 1.8 TFSI S tronic', 192)
>>> c
Car(brand='Audi', model='A1', configuration='Sport 1.8 TFSI S tronic', hp=192)
>>> db.register(Point, Car) # necessary to read tuples
In addition to the methods which the set type provides, there are convenience methods (insert, delete) that handle multiple tuples at once.
>>> db.add(p1) >>> db.remove(p1) >>> db.insert(p1, p2) >>> db.delete(p1, p2) >>> db.insert([p1], [[p1], p2]) >>> db.insert(c) >>> db.insert([c, p1]) # tuples may be of different types
Of course, sqlitent also supports membership checking and counting:
>>> d = c._replace(configuration='1.6 TDI S tronic', hp=116) >>> d in db False >>> len(db) 3 >>> db.insert(d) >>> d in db True >>> len(db) # ...now we have 4 unique tuples in the database. 4
There are various ways to retreive tuples from the database:
>>> p3 = db.one(Point) # not deterministic >>> p3 Point(x=11, y=22) >>> p3 = db.one(p3) # deterministic (since p3 is fully specified) >>> p3 in db True >>> db.pop(p3) # remove and return Point(x=11, y=22) >>> p3 in db False >>> db.pop(Point) # not deterministic Point(x=33, y=22) >>> db.pop(Point) # returns None since there are no more Point tuples >>>
Obviously there are also functions to retrieve or pop multiple values out of the database. sqlitent also supports fuzzy matching on text fields and filter functions:
>>> cs = db.many(Car) # get all cars
>>> cs
<generator object _sqlitent_iter at 0x10f39bb48>
>>> list(cs)
[Car(brand='Audi', model='A1', configuration='Sport 1.8 TFSI S tronic', hp=192),
Car(brand='Audi', model='A1', configuration='1.6 TDI S tronic', hp=116)]
>>> d = list(db.popmany(Car, configuration=fuzzy('%TDI%')))
>>> any(x in db for x in d) # we removed all TDI cars from the database
False
>>> list(db.many(Car, hp=lambda v: v > 150))
[Car(brand='Audi', model='A1', configuration='Sport 1.8 TFSI S tronic', hp=192)]
>>> list(db.many(Car, brand='Kia'))
[]
This library is MIT licensed.
Metadata
Release files for sqlitent 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlitent-0.2.1.tar.gz | 5.4 kB | Without provenance | Details for sqlitent-0.2.1.tar.gz |
Release files / sqlitent-0.2.1.tar.gz
| Download URL | sqlitent-0.2.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1bac70edda04f90efb2b40ed9bdb4a0e9a63a0bec2e42fb2ced72e9c77fe733
|
|
BLAKE2b-256 checksum How to use checksums |
5fc6b7988f1478e6b403c839abaa37edb5a13c1974fcbc3a673b3f9f9b34b1f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sqlitent 0.2.1
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.