Simple helper
Project description
slimhelper
Simple helpers
DbHelper:
constructor:
config : Database connection params
db_type(str): Database type
usage:
# SQlite:
from slim_helper.db_helper import DbHelper
config = {dbname:':memory:'}
with DbHelper(config,'sqlite') as db:
db.execute("""
CREATE TABLE foo (
id INTEGER PRIMARY KEY ,
txt TEXT
)
""")
db.execute("insert into foo values(?,?)",[1,'a'])
db.execute("insert into foo values(?,?)",[2,'b'])
db.execute("insert into foo values(?,?)",[3,'c'])
db.commit()
result = db.query("select * from foo where id=? and txt=?", [2, 'b'])
print(result)
# Or
db=DbHelper(config,'sqlite')
db.open()
...
db.close()
# PostgreSQL:
config={'host':'localhost','port':'5432','dbname':'foobar','user':'foobar','password':'foobar'}
with DbHelper(config,'postgresql') as db:
db.execute("""
CREATE TABLE foo (
id INTEGER PRIMARY KEY ,
txt TEXT
)
""")
db.execute("insert into foo values(%s,%s)",[1,'a'])
db.execute("insert into foo values(%s,%s)",[2,'b'])
db.execute("insert into foo values(%s,%s)",[3,'c'])
db.commit()
result = db.query("select * from foo where id=%s and txt=%s", [2, 'b'])
print(result)
# Or
db=DbHelper(config,'postgresql')
db.open()
...
db.close()
ParallelHelper:
multiprocessing.Pool helper
constructor:
task (Task): Task object.
arguments (Iterable[Iterable]):arguments list.
parallel (int): parallel
usage:
from slim_helper.parallel_helper import Pool, Task
def test(a: int, b: str):
print(a, b)
return str(a)+b
p1 = (1, 'a')
p2 = (2, 'b')
p3 = (3, 'c')
task = Task(test)
params = (p1, p2, p3, p1, p2, p3)
pool = Pool(task, params, 2)
r = pool.start()
print(r)
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
slim_helper-1.0.2.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for slim_helper-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcf183efabca17915d06a8740cba46be75a49dec90d923c6803276f35f09492f |
|
MD5 | 47e04c17e64fea67897f51315636e963 |
|
BLAKE2b-256 | 208209baf6b645da018a46cb35443b1312c31d1460b33ba1915e13a0b98d43af |