nbox.utils
Utility objects and functions.
This has a couple of cool things:
get_logger
: a master logger for nbox, this can be modified to log through anythingisthere
: a decorator that checks if a package is installed, if not it raises an error It is more complicated than it needs to be because it is seedling for a way to package functions and code together so that it can be used in a more dynamic way.get_files_in_folder
: a function that returns all files in a folder with a certain extensionfetch
: a function that fetches a url and caches it intempdir
for faster loadingget_random_name
: a function that returns a random name, ifTrue
is passed returns anuuid4()
for truly random names :)hash_
: a function that returns a hash of any python object, string is accurate, others might be anything, but atleast it returns something.folder/join
: to be used in pair,join(folder(__file__), "server_temp.jinja")
means relative path "../other.py". Scattered throughout the codebase, the super generic name will bite me.to_pickle/from_pickle
: to be used in pair,to_pickle(obj, "path")
andfrom_pickle("path")
to save and load python objects to disk.DBase
: सस्ता-protobuf (cheap protobuf), can be nested andget_dict
will get for all childrenPoolBranch
: Or how to use multiprocessing, but blocked so you don't have to give a shit about it.
Functions
functionlog_traceback
[source]functiondeprecation_warning
[source]functionload_module_from_path
[source]Checks all the packages
functionget_files_in_folder
[source]Get files with ext
in folder
functionfetch
[source]Fetch and cache a url for faster loading, force
re-downloads
functionfolder
[source]get the folder of this file path
functionjoin
[source]convienience function for os.path.join
Save an object to a pickle file
Load an object from a pickle file
functionpy_to_bs64
[source]functionpy_from_bs64
[source]functionto_json
[source]functionfrom_json
[source]functionget_assets_folder
[source]functionget_random_name
[source]Get a random name, if uuid
is True
, return a uuid4
functionhash_
[source]Hash sting of any item
functionget_mime_type
[source]functionthreaded_map
[source]inputs is a list of tuples, each tuple is the input for single invocation of fn. order is preserved.
functionhard_exit_program
[source]Classes
classenv
[source]functionset
[source]functionget
[source]classFileLogger
[source]function__init__
[source]functionlog
[source]classDBase
[source]function__init__
[source]functionget
[source]functionget_dict
[source]function__repr__
[source]functionjson
[source]classSimplerTimes
[source]functionget_now_datetime
[source]functionget_now_float
[source]functionget_now_i64
[source]functionget_now_str
[source]functionget_now_pb
[source]functionget_now_ns
[source]functioni64_to_datetime
[source]