Skip to main content

Python common basic utilities for almirai projects.

Project description

Python common utils

async lrc cache

LRU cache for asyncio

async_lru 1.0.3

from al_utils.alru import alru_cache

@alru_cache(maxsize=128, typed=False)
def test():
    pass

sync to async

Make sync function as async

from al_utils.async_util import async_wrap

@async_wrap
def test():
    pass

# equals to
async_wrap(test())

# equals to
async def test():
    pass

async to sync

Make async function as sync

from al_utils.async_util import run_async
@run_async
async def test():
    pass

# equals to
run_async(test())

# equals to
def test():
    pass

logger

Create logger easier to print log to console and save logs at the same time.

Logger name is current package name split by dot.

It contains a default logger config.

It will save infos to ./logs/info/ and errors to ./logs/error/. Log files split in each week.

from al_utils.logger import Logger

logger = Logger(class_name='').logger

singleton

Singleton container.

Support multiple container.

from al_utils.singleton import Singleton

# set class to container
class Test(Singleton):
    pass


from al_utils.singleton import resolve

test = resolve(Test)

If meta class conflict, using merge_meta to resolve it.

from al_utils.singleton import Singleton
from al_utils.meta import merge_meta

class Test(merge_meta(Singleton, AnothClass)):
    pass

Or, without extends, add class or instance in low-level functions.

from al_utils.singleton import add, add_type

class Test1:
    pass

test1 = Test1()
add(test1)

class Test2:
    pass

add_type(Test2)

print colored messages

Print message to console with custome color(text color, background color) and style(light, normal, bold, ...)

from al_utils.console import ColoredConsole

# light
ColoredConsole.debug('This is a debug.')
# green
ColoredConsole.success('This is a success.')
# yellow
ColoredConsole.warn('This is a warning.')
# red, stderr
ColoredConsole.error('This is a error.')

# custome colored text

# set io(stdout or stderr) start colored.
ColoredConsole.set(style, text_color, bg_color, io)

# print custome colored text
ColoredConsole.print('Costome color text.')

# unset, clear all style and color sets.
ColoredConsole.unset(io)

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

al-utils-almirai-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

al_utils_almirai-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file al-utils-almirai-0.1.0.tar.gz.

File metadata

  • Download URL: al-utils-almirai-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for al-utils-almirai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c5707e29c15ebd75a04cd65133069fbd03aea1e6603d9553295e6f23cc0229d1
MD5 245bf30929729461377233f810f17715
BLAKE2b-256 735a18bcdbd0f46a14716b37282d8e536d8c339ff720d20d3cf70a3a75eb6b00

See more details on using hashes here.

File details

Details for the file al_utils_almirai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for al_utils_almirai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15fe97ea5fe8e173905cce62c278837e56c839e9f43518e9d826e181171410ad
MD5 f219e98bc32af8f2f0619e8cf3e023b5
BLAKE2b-256 188a33b8d108425789acce8eeca6eef52b705625ea764c02c9bc6f6cf1befd8d

See more details on using hashes here.

Supported by

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