Skip to main content

Base library of python 3.6+ and asyncio, include log, config, event, metric etc.

Project description

basepy

Basic library for python 3.6+, includes:

  • config loader
  • structure logger
  • program metrics (statsd)
  • exception logger (via sentry)
  • datastructures for asyncio

log

Very simple and powerful log system, support structure log. It's not depends on python builtin logging module.

import asyncio
from basepy.asynclog import logger

logger.add("stdout")

async def main():
    await logger.info("hello")
    await logger.info("stuct", a=1, b=2, hello='world')


asyncio.run(main())

And the code will generated.

[2020-02-01 11:42:07 +0800] [local.72267] [INFO] [hello]
[2020-02-01 11:42:07 +0800] [local.72267] [INFO] [stuct] [a = 1] [b = 2] [hello = "world"]

config

Config module is easy and powerful settings configuration with following features.

  1. keep secrets related in sperate file .secrets.toml
  2. keep local config in sperate file settings.local.toml or .secrets.local.toml, the local settings will override the settings for the same key.

So, config files should looks like

application
├── .secrets.local.toml
├── .secrets.toml
├── settings.local.toml
└── settings.toml

The .secrets.toml should contains several keys, like

signing_secret = "local_a"
access_token = "local_b"

To access secrets in program, just use settings.secrets

from basepy.config import settings

print(settings.secrets.signing_secret) # will print "local_a"

The settings.toml can contains very complex setting, for example

[log]
    handlers = ["stdout", "local_fluent"]

    [log.stdout]
    handler_type = "stdout"
    level = "debug"

    [log.local_fluent]
    handler_type = "fluent"
    host = "127.0.0.1"
    port = 24224
    tag = "basepy"
    level = "info"

To access normal setting, just use settings.key

from basepy.config import setting
print(setting.log.handlers)

more

Please refer the docs directory.

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

basepy-0.3.5.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

basepy-0.3.5-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file basepy-0.3.5.tar.gz.

File metadata

  • Download URL: basepy-0.3.5.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for basepy-0.3.5.tar.gz
Algorithm Hash digest
SHA256 dd149d823a8778deb9ecbc1105e3dad316ad75797b5a7766b8a77ffc69b64577
MD5 256831fcd57f609aa9d6b0a5b3a2ed6c
BLAKE2b-256 b6779a5ec6589eb9d89049925bbbcd42bb899ecaa0a28ebb241c99cf3e73cde2

See more details on using hashes here.

File details

Details for the file basepy-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: basepy-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for basepy-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ea8b5a02ae642965619e967e23945bbb5a391e90b0d721c5ce178adc28acda3d
MD5 31ba603a3edc1a596216a4ce179a379b
BLAKE2b-256 9ce4503d1deed24dd79553554d278054bd465a910b3b46012a0cee97993e05f1

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