Skip to main content

Python utils

Project description

Tested in Python2.7, Python3.4.


You can do:

from __future__ import print_function

print('x', 'y', sep=',')

But I can not do:

from __future__ import print_function

parameters = ('x', 'y', sep=',')

With callit, I can do similar thing:

from __future__ import print_function
from yxpy.callit import CallIt

parameters = CallIt('x', 'y', sep=',')

Sometimes, you may use Parameters(similar to CallIt):

from __future__ import print_function
from yxpy.callit import Parameters

parameters = Parameters('x', 'y', sep=',')


Usually, dictionary can be used like this:

d = dict(a=1)
d['b'] = 2
x = d['a'] + d['b']

The members in dictionary can only be accessed by [], But in some other languages(eg. javascript), they can be access by .:

d.b = 2
x = d.a + d.b

With dotit, you can do same thing in similar manner, dotit provide thress class to do it.


from dotit import DotDict
d = DotDict(a=1)
d.b = 2
x = d.a + d.b

DotOrderedDict, inherit from collections.OrderedDict:

...     # similar to DotDict

DotIt, if you already have a dict like object, you can wrapper with DotIt:

d = dict(a=1, b=2)
d = DotIt(d)
x = d.a + d.b

DotIt can also deal with nest dict:

d = dict(a=dict(aa=1, ab=2), b=2)
d = DotIt(d)
x = d.a.aa + d.a.ab


Load or reload python object

import module:

import loadit

load moudule:

mod = loadit.load_it('mymodule')

load function:

func = loadit.load_it('mymodule.func')

load class:

MyClass = loadit.load_it('mymodule.MyClass')

reload module:

new_mod = loadit.reload_it(mod)

reload function:

new_func = loadit.reload_it(func)

reload class:

NewMyClass = loadit.reload_it(MyClass)


load config from YAML file, add a include tag.


a: !include a.yaml


name: a


from yxpy import yamlfile



  • SocketHandler(host, port)
  • DatagramHandler(host, port)
  • RedisListHandler(list_name, list_maxsize=1024, host=’localhost’, port=6379, password=None)
  • RedisPublishHandler(self, channel, host=’localhost’, port=6379, password=None)

SocketHandler & DatagramHandler

logging package provide many Handlers, include SocketHandler and DatagramHandler, but the data transmit to server is packed as binary, this module privide simular handler to transmit plain text to server.


socket_handler = SocketHandler(host, port)
datagram_handler = DatagramHandler(host, port)

RedisListHandler & RedisPublishHandler

use Redis as log server, the two handler is just privide a singleway to redis server. to keep simple, the handlers does check the response of redis.


handler = RedisListHandler(list_name=’logtest’, list_maxsize=100, password=’test’) … handler = RedisPublishHandler(channel=’logtest’, password=’test’) …



  • refactoring: import statement in reloadit


  • DotIt support nest dict.


  • add dotit: include DotIt, DotDict, DotOrderedDict


  • add logginghandlers: - SocketHandler - DatagramHandler - RedisListHandler - RedisPublishHandler


  • callit
  • loadit
  • yamlfile

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date (10.1 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page