Common hacks in python.
Project description
common-py
My common Python hacks
Table of Contents
Installation
To install the required dependencies, use:
pip install common-py
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.0.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file ekcommon-1.0.0.tar.gz
.
File metadata
- Download URL: ekcommon-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1f7e5da356722e8f59c112f47a3835dd928776a8c5542a293ff86a0ff794819 |
|
MD5 | 8819099dd7d1102513bac4e5c175c648 |
|
BLAKE2b-256 | 65bd1d12de4b6de2a60fe19e7f69c0a29ddedd82f0f621ec7565d2094ef220aa |
File details
Details for the file ekcommon-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: ekcommon-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 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 | 41b1a674cb6ba6be414f5c3054c73418610bcb9755103c1ecea0f8c7df2c77b4 |
|
MD5 | 077e43896f691f5fa316b8737750ff21 |
|
BLAKE2b-256 | e709537b8f184789e2dbbae00488a6182f5034720c09da637f206c68f7ffb81a |