Skip to main content

Default template for PDM package

Project description

slim-helper

pip install slim-helpe[postgres] # optional dependency: psycopg
pip install slim-helpe[oracle] # optional dependency: oracledb
pip install slim-helpe[all] # all optional dependency

database

from from slim_helper.database import DbHelper,SqliteParams,PostgresParams,OracleParams

# SQlite:
config = SqliteParams(file_name=':memory:')
with DbHelper(config) 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,columns = db.query("select * from foo where id=? and txt=?", [2, 'b'])
    db.execute("drop table foo")
    print(result,columns)
# Or
db = DbHelper(config)
db.open()
...
db.close()


# PostgreSQL:
config=PostgresParams(host='localhost',port=5432,dbname='postgres',user='postgres',password='postgres')
with DbHelper(config) as db:
    db.execute("""
        CREATE TABLE  IF NOT EXISTS 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,columns = db.query("select * from foo where id=%s and txt=%s", [2, 'b'])
    db.execute("drop table foo")
    print(result,columns)
# Or
db = DbHelper(config)
db.open()
...
db.close()


# Oracle:
config = OracleParams(host='localhost',port=1521,service_name='orcl',user='orcl',password='orcl')
with DbHelper(config) as db:
    db.execute("""
        CREATE TABLE FOO (
        id INTEGER PRIMARY KEY ,
        txt VARCHAR2(100)
        )
        """)
    db.execute("insert into FOO values(:1,:2)", [1, 'a'])
    db.execute("insert into FOO values(:1,:2)", [2, 'b'])
    db.execute("insert into FOO values(:1,:2)", [3, 'c'])
    db.commit()
    result,columns = db.query("select * from foo where id=:1 and txt=:2", [2, 'b'])
    db.execute("drop table FOO")
    print(result,columns)
# Or
db = DbHelper(config)
db.open()
...
db.close()

common

# retry decorator
retry(times: int, interval_secs: int)
# timer decorator
timer(func: Callable)
# null value logic function
nvl(*args)

display

# convert number to SI metric prefix
si_prefix(value: float | int)
# convert number to IEC metric prefix
iec_prefix(value: int)

io

# line reader class
LineReader(
    file: Path,
    max_line_size: int,
    sep: bytes = b"\n",
    start_pos: int = 0,
    end_pos: int | None = None,
)
# Get range
read_range_distribute(
    file: Path, n: int, sep: bytes | None = None
)

process

# Execute command function
execute_command(
    cmd: Sequence[str],
    stdin: bytes | None = None,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    dry: bool = False,
)

security

# SHA3-512
sha3_512(obj: Path | str | bytes)

task

# Parallel task executor
ParallelWorker(
    callback: Callable,
    parallel: int = 1,
    max_input: int = 0,
    max_output: int = 0,
)

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-2.5.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slim_helper-2.5.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file slim_helper-2.5.0.tar.gz.

File metadata

  • Download URL: slim_helper-2.5.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.13.2 CPython/3.12.2 Linux/6.8.2-1-default

File hashes

Hashes for slim_helper-2.5.0.tar.gz
Algorithm Hash digest
SHA256 273f0d2d69fa04af958bacd1cb9d5f44d8ca072c1586daa12fe6417da4a0c6db
MD5 69d536424442d5097759a81ae6916f37
BLAKE2b-256 a4d09e77aa0ccafe24a604a50530a9c77d91783b68f841f0597363c0dd8904e3

See more details on using hashes here.

File details

Details for the file slim_helper-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: slim_helper-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.13.2 CPython/3.12.2 Linux/6.8.2-1-default

File hashes

Hashes for slim_helper-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0191219ee468861c1ed63fa2d4aba86fe6f47b3116a586cbfd9d511861bd9ff1
MD5 2db490ad70bdad2c3945998526481dd6
BLAKE2b-256 4fc12ec3f4e64a549fca58b5c3b1877f0040cdd722f40a2f8c3a58708fd8127b

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