Common hacks in python.
Project description
common-py
My common Python hacks
Table of Contents
Installation
To install the required dependencies, use:
pip install ekcommon
To use:
from ekcommon import *
or
from commonpy import *
Usage
Example 1: Handling Exceptions
from commonpy.simpleexceptioncontext import SimpleExceptionContext
callback = lambda e: self._eng.statusChanges.emit(f'Exception in processing {e}')
with SimpleExceptionContext('exception in processing',callback=callback):
ret=self.process_internal(ls)
logging.debug(f"process end {ret}")
return ret
In this example , a callback is called when the exception occurs.
Example 2: Exception Handling with Decorators
@simple_exception_handling(err_description='error in get_symbol_history', return_succ=(None, []), never_throw=True)
@excp_handler(polygon.exceptions.BadResponse, handler=excphandler)
def get_symbol_history(sym, startdate, enddate, iscrypto=False):
# Your code to fetch symbol history here
pass
Example 3: Date and Time Utilities
from commonpy import localize_it, unlocalize_it
import datetime
dt = datetime.datetime.now()
localized_dt = localize_it(dt)
unlocalized_dt = unlocalize_it(localized_dt)
Features
- SimpleExceptionContext: Context manager for handling exceptions with customizable logging and traceback formatting.
- Date and Time Utilities: Functions to localize and unlocalize datetime objects.
- Functional Helpers: Various lambda functions for filtering dictionaries and mapping lists.
Contributing
Contributions are welcome! Please fork this repository and submit a pull request.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ekcommon-1.0.2.tar.gz
(6.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ekcommon-1.0.2-py3-none-any.whl
(15.4 kB
view details)
File details
Details for the file ekcommon-1.0.2.tar.gz.
File metadata
- Download URL: ekcommon-1.0.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abb4f9fa35affc4a4f39588fed9b17409a8185afcce9ca40e05928aa6f0df9ed
|
|
| MD5 |
583c7219986355d6634c27428df0d374
|
|
| BLAKE2b-256 |
079fa6b3a9ad4ba529b06372edf5ac01430708ecad974f85bcffc8da76f27d5d
|
File details
Details for the file ekcommon-1.0.2-py3-none-any.whl.
File metadata
- Download URL: ekcommon-1.0.2-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fb75bdae80d3162173886a3a44446553efbcd6732b51bb509597b74c7446ad9
|
|
| MD5 |
c0fdaf17cee91f2d1b37a11bf63aab77
|
|
| BLAKE2b-256 |
496426ace9597dd1d0737c08ce09c69470ead63629b33083930467df747757ad
|