Skip to main content

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


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)

Uploaded Source

Built Distribution

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

ekcommon-1.0.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

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

Hashes for ekcommon-1.0.2.tar.gz
Algorithm Hash digest
SHA256 abb4f9fa35affc4a4f39588fed9b17409a8185afcce9ca40e05928aa6f0df9ed
MD5 583c7219986355d6634c27428df0d374
BLAKE2b-256 079fa6b3a9ad4ba529b06372edf5ac01430708ecad974f85bcffc8da76f27d5d

See more details on using hashes here.

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

Hashes for ekcommon-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8fb75bdae80d3162173886a3a44446553efbcd6732b51bb509597b74c7446ad9
MD5 c0fdaf17cee91f2d1b37a11bf63aab77
BLAKE2b-256 496426ace9597dd1d0737c08ce09c69470ead63629b33083930467df747757ad

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