{ "info": { "author": "Jonathan Morgan", "author_email": "jonathan.morgan.007@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Framework :: Jupyter", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Database :: Database Engines/Servers", "Topic :: Text Processing", "Topic :: Text Processing :: Markup :: HTML", "Topic :: Utilities" ], "description": "# python\\_utilities\n\nv.1.0.2: [![DOI](https://zenodo.org/badge/6323399.svg)](https://zenodo.org/badge/latestdoi/6323399)\n\nv.1.0.1: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3523239.svg)](https://doi.org/10.5281/zenodo.3523239)\n\n\n\nPython utility classes (should work in either Python 2 or 3). Includes the following files:\n\n- __/analysis/__\n\n - __/analysis/statistics/confusion_matrix_helper.py__ - helper class `ConfusionMatrixHelper`for working with confusion matrices, usually because you have run a classification model and are trying to assess its quality.\n - __/analysis/statistics/stats_helper.py__ - helper class `StatsHelper` for help with statistics not implemented in a statistical package. Includes Krippendorff's Alpha, percent agreement, and Potter's Pi, for assessing interrater reliability/agreement.\n - __/analysis/statistics/tests.py__ - unit tests.\n\n- __/bagit/__\n\n - __/bagit/bagit_python.ipynb__ and __/bagit/bagit_python.py__ - bagit python client example code, same code in both files, one is a jupyter notebook, one is a plain Python file.\n\n- __/beautiful\\_soup/__\n\n - __/beautiful\\_soup/beautiful\\_soup\\_helper.py__ - `BeautifulSoupHelper` class that implements helper methods for common things you do with BeautifulSoup, like getting child text and encoding HTML entities. Built against BeautifulSoup 3, updated to import BeautifulSoup 4, work just fine far as I can tell...\n\n- __/booleans/__\n\n - __/booleans/boolean\\_helper.py__ - `BooleanHelper` class with method to convert non-boolean values to boolean type based on valid known true values (1, 't', 'true', 'y', 'yes').\n\n- __/data__\n\n - __/data/data\\_functions.py__ - a set of reusable functions for various data tasks that includes pandas, RDBMS, CSV, and SAS processing.\n\n- __/database__\n\n - __/database/database\\_helper\\_factory.py__ - `Database_Helper_Factory` class provides a class method you can use to pull in either a postgresql or mysql database helper, so you can write code that functions the same way for either, allowing easier switching between the two.\n - __/database/database\\_helper.py__ - `Database_Helper` abstract class encapsulates basic logic for dealing with creating connections and cursors using a Python DB API library. Not fancy. Opens, creates cursors and keeps track of all cursors it creates, and closes all related cursors and connection when you call close(). Nothing more.\n - __/database/psycopg2\\_helper.py__ - `psycopg2_Helper` class encapsulates basic logic for dealing with creating connections and cursors using the psycopg2 library. Not fancy. Opens and closes, nothing more.\n - __/database/MySQLdb\\_helper.py__ - `MySQLdb_Helper` class encapsulates basic logic for dealing with creating connections and cursors using the MySQLdb library. Not fancy. Opens and closes, nothing more.\n - __/database/PyMySQL\\_helper.py__ - `PyMySQL_Helper` class encapsulates basic logic for dealing with creating connections and cursors using the PyMySQL library. Not fancy. Opens and closes, nothing more.\n\n- __/dictionaries/__\n\n - __/dictionaries/dict\\_helper.py__ - `DictHelper` class contains a function to retrieve a dict values as strings, integers, and lists that also accept a default, so you can convert to types and define default yourself when you look things up in a dict.\n\n- __/django\\_utils/__\n\n - __/django\\_utils/django\\_ajax\\_selects\\_lookup\\_helper.py__ - includes `LookupParent` class, to allow for easy implementation of robust lookup classes for `django_ajax_selects`.\n - __/django\\_utils/django\\form\\_helper.py__ - has a class `DjangoFormHelper` that includes helper class methods for working with forms: `is_form_empty()`; `is_value_empty()`; `data_to_html_as_hidden_inputs()`, and then classes `FormParent` and `ModelFormParent` that correctly apply these methods to forms and model forms, respectively.\n - __/django\\_utils/django\\_memory\\_helper.py__ - has a class `DjangoMemoryHelper` with a single class method, `free_memory()`, that does everything I know how to do to free up memory in django while a long-running process is running.\n - __/django\\_utils/django\\_model\\_helper.py__ - has a class `DjangoModelHelper` with a single class method, `copy_m2m_values()`, that copies ManyToMany values from one model to another for a field whose name is passed in.\n - __/django\\_utils/django\\_string\\_helper.py__ - extends `StringHelper` class from `strings/string_helper.py`, updating the `convert_to_unicode()` method to use Django's built-in method.\n - __/django\\_utils/django\\_test\\_case\\_helper.py__ - has a class `DjangoTestCaseHelper` that extends `django.test.TestCase` and is itself meant to be extended by test case classes that wnat to use the help it provides. For now, has a single method, `validate_string_against_file_contents()`, for comparing a string with the contents of a file using difflib.\n - __/django\\_utils/django\\_view\\_helper.py__ - has a class `DjangoViewHelper` with a single class method, `get_request_data()`, that retrieves data from a request passed in, whether the request is GET or POST.\n - __/django\\_utils/query\\_filter.py__ - `QueryFilterHelper` class, just extends `QuerySetHelper` for backward compatibility.\n - __/django\\_utils/queryset\\_helper.py__ - `QuerySetHelper` class that contains memory-efficient ways of iterating over large QuerySets, and also a few convenience methods for adding date and primary key filters to a QuerySet.\n - __/django\\_utils/requirements.txt__ - list of packages required by the code in this folder.\n\n- __/email/__\n\n - __/email/email\\_helper.py__ - `EmailHelper` class that contains logic for setting up SMTP server using smtplib, then sending text or HTML email messages.\n - __/email/email\\_test.py__ - basic email code on which EmailHelper is based, as an example.\n\n- __/etl/__ - Basic ETL framework that includes:\n\n - objects to capture a simple ETL specification:\n\n - __/etl/etl\\_attribute.py__ - Class `ETLAttribute` holds details on a particular property/field within a source file that is being loaded.\n - __/etl/etl\\_entity.py__ - Class `ETLEntity` holds details on a set of attributes being loaded, practically speaking the set of columns/properties/fields in each record from a file that is being loaded.\n - __/etl/etl\\_error.py__ - Class `ETLError` is an Error child class used to signal unrecoverable problems in ETL.\n\n - ETL processor family\n\n - __/etl/etl\\_processor.py__ - Class `ETLProcessor` contains parts of ETL loader that are shared regardless of source or destination.\n - ---> __/etl/etl\\_object\\_loader.py__ - Class `ETLObjectLoader` contains parts of ETL loader that pertain to loading into instance of Python objects (and if you are loading into something more common, there are better tools). Extends `ETLProcessor`.\n - --------> __/etl/etl\\_django\\_model\\_loader.py__ - Class `ETLDjangoModelLoader` contains parts of ETL loader that pertain to loading data into the specific type of object that is an instance of a django model (primarily looking to see if record matching ID column values already exists, so we update, rather than duplicate). Extends `ETLObjectLoader`.\n - ------------> __/etl/etl\\_from\\_excel\\_with\\_headers.py__ - Class `ETLFromExcelWithHeaders` contains the code to load data from an Excel document into any django model class instance based on an ETL specification contained in an `ETLEntity` specifiation instance. Extends `ETLDjangoModelLoader`.\n - ------------> __/etl/etl\\_from\\_dictionary\\_iterable.py__ - Class `ETLFromDictionaryIterable` contains the code to load data from a list of data dictionary objects (from JSON, CSVDictReader, or other source) into any django model class instance based on an ETL specification contained in an `ETLEntity` specifiation instance. Extends `ETLDjangoModelLoader`.\n\n - __/etl/loadable\\_django\\_model.py__ - Class `LoadableDjangoModel` is a django abstract class that extends Django's `models.Model` class and contains all the methods each of the \"`ETLFrom...`\" classes in this package expect so they can load to a Django model class. This class is intended to show the fields and methods that have to be present in a django model for the ETL loaders here to run without needing any modification. It can either be imported into simple Django applications and then extended, or copied and altered to fit a more complex object model.\n\n- __/exceptions/__\n\n - __/exceptions/exception\\_helper.py__ - `ExceptionHelper` class that contains logic for printing exception messages, and also for emailing a summary if email is set up in the isntance.\n\n- __/integers/__\n\n - __/integers/integer_helper.py__ - helper class `IntegerHelper` with a single class method, `is_valid_integer()`, that accepts a value and returns True if it contains a valid integer, False if not.\n - __/integers/tests.py__ - unit tests.\n\n- __/json/__\n\n - __/json/json\\_helper.py__ - `JSONHelper` class that contains logic for pretty printing JSON and escaping all string values within a JSON object.\n\n- __/lists/__\n\n - __/lists/list\\_helper.py__ - `ListHelper` class that contains class method `get_value_as_list()` that accepts a value, tries to convert it to a list.\n\n- __/logging/__\n\n - __/logging/logging\\_helper.py__ - `LoggingHelper` class contains instance variables to hold python `logging` logger instance and application name used when getting logger, and methods to get and set them. The get_logger() method makes a new one using the application name if none is already present in the instance. Can be used on its own, or as a parent class to add this stuff to an existing class.\n - __/logging/summary\\_helper.py__ - `SummaryHelper` class that contains logic for capturing and outputting timing and auditing information.\n\n- __/network__\n\n - __/network/http\\_helper.py__ - `Http_Helper` class that contains logic for checking if a URL has been redirected, and if so, storing redirect information including status code and redirect URLs.\n - __/network/network\\_helper.py__ - `Network_Helper` class contains instance methods for parsing URL strings and plucking out different known, standard pieces (domain, trimmed domain, just path - no query string, and everything after the domain).\n - __/network/openanything.py__ - Contains `SmartRedirectHandler` class that keeps track of redirect hops for urllib2, logic to support Http_Helper, from the Dive Into Python site (http://www.diveintopython.net/download/diveintopython-examples-5.4.zip)\n\n- __/objects/__\n\n - __/objects/object\\_helper.py__ - `ObjectHelper` class contains logic for detecting attributes in a given class (like the vars() method, only a little fancier).\n\n- __/parameters/__\n\n - __/parameters/param\\_container.py__ - `ParamContainer` class contains logic for defining, loading, accessing, and outputting parameters stored in a dictionary.\n\n- __/R/__\n\n - __/R/rserve_helper.py__ - `RserveHelper` class contains logic for working with the Rserve Python-R integration package.\n\n- __/rate\\_limited/__\n\n - __/rate\\_limited/basic\\_rate\\_limited.py__ - `BasicRateLimited` is a non-parallel parent class that contains variables and code for rate-limiting. Details on extending TK below, in Usage Section.\n\n- __/status/__\n\n - __/status/status\\_container.py__ - `StatusContainer` class that can be used as a single return-type that contains detailed status information including status code, status message, nested name value pairs (which can include exceptions as values), and a nested status container from a child call.\n\n- __/sequences/__\n\n - __/sequences/sequence\\_helper.py__ - `SequenceHelper` class for methods to help with working with Sequences (Lists, etc.). Only method there now is KnuthMorrisPratt(), used to find index in list of places where another list is reproduced in its entirety (looking for subsequences within sequences).\n\n- __/strings/__\n\n - __/strings/html\\_helper.py__ - `HTMLHelper` class to help with parsing and dealing with HTML strings. Right now, has one static method, `remove_html()`, that removes HTML from a string, allowing for a list of HTML elements you want left in, and within those elements, a list of attributes you want left in. If something is not in one of those lists, it will be removed.\n - __/strings/string\\_helper.py__ - `StringHelper` class with methods to help with unicode encoding, stripping HTML from strings.\n - __/strings/tests.py__ - unit tests.\n\n## Installation\n\n### Option 1: pip for stable version\n\nUse pip:\n\n (sudo) pip install python-utilities-jsm\n\n### Option 2: latest from github\n\nClone this repository and place it somewhere in your PYTHON\\_PATH, including the base \"python\\_utilities\" directory. The easiest way to use these libraries with a Django site is to clone this repository into the site's folder alongside other applications, so these utilities are a part of the same python path as other django apps. These utilities are used by other of my django applications, as well. They can also be used outside of django.\n\nDependencies are listed below. You can install them individually, or you can just use the `requirements*.txt` files, which lists them all out, to install them all at once using pip. The command to install base packages, without database-specific support:\n\n (sudo) pip install -r python_utilities/requirements.txt\n\n\n### For either option, database packages\n\nFor database packages, you'll need to load the requirements file for each database you want to interact with (right now `requirements_pgsql.txt` for postgresql and `rewuirements_mysql.txt` for MySQL). Whichever you install, you'll also need to make sure you installed the client and client-dev libraries for each database you use.\n\n### /beautiful\\_soup/*\n\nRequires the Beautiful Soup 4 package, installed via pip:\n\n (sudo) pip install BeautifulSoup4\n\nIf you are planning on using Beautiful Soup's \"UnicodeDammit\" class, you also should install chardet and/or cchardet:\n\n (sudo) pip install chardet\n (sudo) pip install cchardet\n\n### /strings/html_helper.py\n\nrequires bleach, a library for selectively parsing HTML and XML:\n\n (sudo) pip install bleach\n\nand requires the Beautiful Soup 4 package, installed via pip:\n\n (sudo) pip install BeautifulSoup4\n\n### /database/MySQLdb\\_helper.py\n\nBefore you can connect to MySQL with this code, you need to do the following:\n\n- install the MySQL client if it isn't already installed. On linux, you'll also need to install a few dev packages (python-dev, libmysqlclient-dev) ( [source](http://codeinthehole.com/writing/how-to-set-up-mysql-for-python-on-ubuntu/) ).\n\n- install the MySQLdb python package. To install, you can either install through your operating system's package manager (ubuntu, for example, has package \"python-mysqldb\") or using pip (`sudo pip install MySQL-python`).\n\n### /database/psycopg2\\_helper.py\n\nBefore you can connect to Postgresql with this code, you need to do the following (based on [http://initd.org/psycopg/install/](http://initd.org/psycopg/install/)):\n\n- install the PostgreSQL client if it isn't already installed. On linux, you'll also need to install a few dev packages (python-dev, libpq-dev) ( [source](http://initd.org/psycopg/install/) ).\n\n- install the psycopg2 python package. Install using pip (`sudo pip install psycopg2`).\n\n### /database/PyMySQL\\_helper.py\n\nBefore you can connect to MySQL with this code, you need to do the following:\n\n- install the PyMySQL python package. To install, use pip (`sudo pip install PyMySQL`) or conda if you are using anaconda (`conda install pymysql`).\n\n### /network/*\n\nRequires you install mechanize, a library that implements a browser client in python, and requests:\n\n (sudo) pip install mechanize\n (sudo) pip install requests\n\n### /strings/*\n\nRequires you to install the \"six\" package, which helps make python code that can run in either python 2 or 3:\n\n (sudo) pip install six\n\n## Usage\n\n### /exceptions/exception\\_helper.py\n\nFor a class you want to use ExceptionHelper for outputting and potentially emailing exception messages:\n\n # import ExceptionHandler\n from python_utilities.exceptions.exception_helper import ExceptionHelper\n\n # import logging\n import logging\n\n # make instance\n my_exception_helper = ExceptionHelper()\n\n # by default, logs to logger with name \"python_utilities.exceptions.exception_helper\".\n # if you want it to log to a different logger name, initialize that logger,\n # then pass it to the set_logger() method. Example:\n #\n # my_logger = logging.getLogger( \"logger_name_example\" )\n # my_exception_helper.set_logger( my_logger )\n\n # By default, ExceptionHelper logs exception information to logging.ERROR.\n # You can set the level at which your exception helper will log messages:\n # my_exception_helper.set_logging_level( logging.DEBUG )\n\n # configure mail settings?\n '''\n smtp_host = 'localhost'\n smtp_port = 1234\n smtp_use_ssl = True\n smtp_username = \"smtp_user\"\n smtp_password = \"smtp_pass\"\n my_exception_helper.email_initialize( smtp_host, smtp_port, smtp_use_ssl, smtp_username, smtp_password ):\n '''\n\n # log an exception\n try:\n\n pass\n\n catch Exception as e:\n\n # log exception.\n exception_message = \"Exception caught for article \" + str( current_article.id )\n\n # no email\n my_exception_helper.process_exception( e, exception_message )\n\n # with email\n # my_exception_helper.process_exception( e, exception_message, True, \"email_subject\" )\n\n #-- END try-catch --#\n\nIf you are going to be in a long-running or looping process, consider initializing at the beginning and storing instance in a variable, so you can reuse it.\n\nAlso, this class extends LoggingHelper, so it can take advantage of that set of functionality as well, outlined below.\n\n### /logging/logging_helper.py\n\nThe `LoggingHelper` class can be used two ways:\n\n1. you can create an instance of it and use that to retrieve a python logger.\n\n # import logging and LoggingHelper\n import logging\n from python_utilities.logging.logging_helper import LoggingHelper\n\n # make a Logger instance.\n my_logger_factory = LoggingHelper()\n\n # set the logger name\n my_logger_factory.set_logger_name( \"test_logger\" )\n\n # get a python logging.logger\n my_logger = my_logger_factory.get_logger()\n\n\n2. You can use it as a parent class for an existing class to add a variable for a logger and a logging application name and methods to get and set each to a class.\n\n # import logging and Logger\n import logging\n from python_utilities.logging.logging_helper import LoggingHelper\n\n # make Logger the parent class\n class MyClass( LoggingHelper ):\n\n # in your __init__() method, call parent __init__(), then set\n # self.logger_name to either __name__ or a name you prefer.\n def __init__( self ):\n\n # call parent's __init__()\n super( MyClass, self ).__init__()\n\n # set self.logger_name\n self.set_logger_name( \"MyClass\" )\n\n #-- END __init__() method --#\n\n # then, to get logger instance, call self.get_logger().\n\n #-- END class MyClass --#\n\n\n### /logging/summary\\_helper.py\n\nHow to use the summary helper:\n\n # import SummaryHelper\n from python_utilities.logging.summary_helper import SummaryHelper\n\n # initialize summary helper - this sets start time, as well.\n my_summary_helper = SummaryHelper()\n\n # auditing variables\n article_counter = -1\n exception_counter = -1\n\n # update the variables\n\n # once you are done:\n\n # set stop time\n my_summary_helper.set_stop_time()\n\n # add stuff to summary\n my_summary_helper.set_prop_value( \"article_counter\", article_counter )\n my_summary_helper.set_prop_desc( \"article_counter\", \"Articles processed\" )\n\n my_summary_helper.set_prop_value( \"exception_counter\", exception_counter )\n my_summary_helper.set_prop_desc( \"exception_counter\", \"Exception count\" )\n\n # output - set prefix if you want.\n summary_string += my_summary_helper.create_summary_string( item_prefix_IN = \"==> \" )\n print( summary_string )\n\nExample output:\n\n ==> Articles processed: 46\n ==> Exception count: 20\n ==> Start time: 2014-12-31 14:32:28.221066\n ==> End time: 2014-12-31 14:32:41.982753\n ==> Duration: 0:00:13.761687\n\n### /network/http_helper.py\n\nThe `Http_Helper` class lets you configure an HTTP request in an instance of `Http_Helper` using its built in storage for request properties and headers, then submit the request using either the urllib2 ([https://docs.python.org/2/library/urllib2.html](https://docs.python.org/2/library/urllib2.html)), mechanize ([http://wwwsearch.sourceforge.net/mechanize/](http://wwwsearch.sourceforge.net/mechanize/)), or requests ([http://docs.python-requests.org/en/latest/](http://docs.python-requests.org/en/latest/)) packages. For a given request and package, you can either get the page itself, or just submit a URL to find its final redirected URL.\n\nExample: using requests package to submit a post request.\n\n # create Http_Helper\n my_http_helper = Http_Helper()\n\n # set http headers\n my_http_helper.set_http_header( \"Content-Type\", \"text/plain\" )\n\n # request type\n my_http_helper.request_type = Http_Helper.REQUEST_TYPE_POST\n\n # place body of request in a variable.\n request_data = \"My dog has fleas, figaro, figaro, figaro!\"\n\n # make the request using requests package:\n requests_response = my_http_helper.load_url_requests( \"http://yahoo.com\", request_type_IN = Http_Helper.REQUEST_TYPE_POST, data_IN = request_data )\n\n # get raw text response:\n requests_raw_text = requests_response.text\n\n # convert to a json object:\n requests_response_json = requests_response.json()\n\n # to make request using mechanize (a full-featured web browser):\n mechanize_response = my_http_helper.load_url_mechanize( \"http://yahoo.com\", request_type_IN = Http_Helper.REQUEST_TYPE_POST, data_IN = request_data )\n\n # to make request using urllib2:\n urllib2_response = my_http_helper.load_url_urllib2( \"http://yahoo.com\", request_type_IN = Http_Helper.REQUEST_TYPE_POST, data_IN = request_data )\n\nTroubleshooting:\n\n- If you are using the requests package and have data that you want to pass to the `load_url_requests()` method in variable `data_IN` that is a unicode string, if that unicode string has any non-ascii characters, you must encode the data before passing it in, else somewhere down in a library, something detects that the data is a unicode string and tries to encode it to \"ASCII\", which fails if there any non-ascii characters. If you encode to UTF-8 before passing the data in, this converts to a byte string, and all works fine.\n\n - An example of the stack trace and exception message you'll see if you have this problem:\n\n File \"/python_utilities/network/http_helper.py\", line 638, in load_url_requests\n response_OUT = requests.post( url_IN, headers = headers, data = data_IN )\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/api.py\", line 99, in post\n return request('post', url, data=data, json=json, **kwargs)\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/api.py\", line 49, in request\n response = session.request(method=method, url=url, **kwargs)\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/sessions.py\", line 461, in request\n resp = self.send(prep, **send_kwargs)\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/sessions.py\", line 573, in send\n r = adapter.send(request, **kwargs)\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/adapters.py\", line 370, in send\n timeout=timeout\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py\", line 518, in urlopen\n body=body, headers=headers)\n File \"/.virtualenvs/sourcenet/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py\", line 330, in _make_request\n conn.request(method, url, **httplib_request_kw)\n File \"/usr/lib/python2.7/httplib.py\", line 1001, in request\n self._send_request(method, url, body, headers)\n File \"/usr/lib/python2.7/httplib.py\", line 1035, in _send_request\n self.endheaders(body)\n File \"/usr/lib/python2.7/httplib.py\", line 997, in endheaders\n self._send_output(message_body)\n File \"/usr/lib/python2.7/httplib.py\", line 854, in _send_output\n self.send(message_body)\n File \"/usr/lib/python2.7/httplib.py\", line 826, in send\n self.sock.sendall(data)\n File \"/usr/lib/python2.7/socket.py\", line 224, in meth\n return getattr(self._sock,name)(*args)\n UnicodeEncodeError: 'ascii' codec can't encode character u'\\u2014' in position 98: ordinal not in range(128)\n\n - An example of encoding using StringHelper:\n\n encoded_data = StringHelper.encode_string( unicode_string, StringHelper.ENCODING_UTF8 )\n\n - An example of encoding using codecs:\n\n encoded_data =\n\n### /parameters/param\\_container.py\n\nUsage:\n\n # import ParamContainer\n from python_utilities.parameters.param_container import ParamContainer\n\n # make an instance\n my_param_container = ParamContainer()\n\n # define parameters (for outputting debug, nothing more at this point)\n my_param_container.define_parameter( \"test_int\", ParamContainer.PARAM_TYPE_INT )\n my_param_container.define_parameter( \"test_string\", ParamContainer.PARAM_TYPE_STRING )\n my_param_container.define_parameter( \"test_list\", ParamContainer.PARAM_TYPE_LIST )\n\n # load parameters in a dict\n my_param_container.set_parameters( params )\n\n # load parameters from a django HTTP request\n my_param_container.set_request( request )\n\n # get parameter value - pass name and optional default if not present.\n test_int = my_param_container.get_param( \"test_int\", -1 )\n test_string = my_param_container.get_param( \"test_string\", \"\" )\n test_list = my_param_container.get_param( \"test_list\", [] )\n\n # get param as int\n test_int = my_param_container.get_param_as_int( \"test_int\", -1 )\n\n # get param as str\n test_string = my_param_container.get_param_as_str( \"test_string\", -1 )\n\n # get param as list - pass in name, optional default, list delimiter string (defaults to \",\")\n test_int = my_param_container.get_param_as_list( \"test_int\", -1, delimiter_IN = \",\" )\n\n### /rate\\_limited/basic\\_rate\\_limited.py\n\nFor a class you want to be rate-limited:\n\n- have that class import and extend `BasicRateLimited`.\n\n # import\n from python_utilities.rate_limited.basic_rate_limited import BasicRateLimited\n\n # class definition\n def class SampleClass( BasicRateLimited ):\n\n- in that class's `__init__()` method, call the parent `__init__()` method, then set instance variable `rate_limit_in_seconds` to the minimum number of seconds you want between requests (can be a decimal).\n\n def __init__( self ):\n\n # call parent's __init__()\n super( SampleClass, self ).__init__()\n\n # declare variables\n\n # limit to no more than 4 per second\n self.rate_limit_in_seconds = 0.25\n\n #-- END method __init__() --#\n\n- At the start of each transaction, call the `self.start_request()` method to let the code know you're starting a request.\n- Once the request is done, call `continue_collecting = self.may_i_continue()` this method will block if you have to wait, will return true if it is OK to continue, will return False if some error occurred.\n- In your control structure, always check the result of `may_i_continue()` before continuing.\n\n## License:\n\nCopyright 2015-present (2019) Jonathan Morgan\n\nThis file is part of [http://github.com/jonathanmorgan/python\\_utilities](http://github.com/jonathanmorgan/python_utilities).\n\npython\\_utilities is free software: you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\npython\\_utilities is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License\nalong with [http://github.com/jonathanmorgan/python\\_utilities](http://github.com/jonathanmorgan/python_utilities). If not, see\n[http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jonathanmorgan/python_utilities", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "python-utilities-jsm", "package_url": "https://pypi.org/project/python-utilities-jsm/", "platform": "", "project_url": "https://pypi.org/project/python-utilities-jsm/", "project_urls": { "Homepage": "https://github.com/jonathanmorgan/python_utilities" }, "release_url": "https://pypi.org/project/python-utilities-jsm/1.1.0/", "requires_dist": [ "bagit", "beautifulsoup4", "bleach", "cchardet", "chardet", "ipykernel", "openpyxl", "regex", "requests", "six", "w3lib" ], "requires_python": ">=3.6", "summary": "Myriad python utilities.", "version": "1.1.0", "yanked": false, "yanked_reason": null }, "last_serial": 12695178, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d6d932bd57bb3fbcd7890a0d3b8ed90e", "sha256": "87162c2b48d8e110d274532da8a52d3385784cba8d1384c2e7fdbd307ddfc1b7" }, "downloads": -1, "filename": "python_utilities_jsm-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d6d932bd57bb3fbcd7890a0d3b8ed90e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 141408, "upload_time": "2019-10-30T02:06:50", "upload_time_iso_8601": "2019-10-30T02:06:50.444788Z", "url": "https://files.pythonhosted.org/packages/ec/16/03f4f2946274ca1b33e79eb357c5112fcbe19df122824fa2afaab74dc1b7/python_utilities_jsm-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "79a137b784ea2d4d140fd68e5a4f4a9d", "sha256": "32174f0b5efc683d9efb401abb498ae6c73a3b519a777f811386156677b5bce9" }, "downloads": -1, "filename": "python-utilities-jsm-1.0.0.tar.gz", "has_sig": false, "md5_digest": "79a137b784ea2d4d140fd68e5a4f4a9d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 106513, "upload_time": "2019-10-30T02:06:53", "upload_time_iso_8601": "2019-10-30T02:06:53.283420Z", "url": "https://files.pythonhosted.org/packages/2c/b9/6c2f7bf50ac0ce30510e2f933c974189d68e8a720e30fa26ac826cfa1ef2/python-utilities-jsm-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "5752ea1b7a80f0a04aad0fef91f5c33f", "sha256": "45f91e2a692643ed35dd7eac19614f93c3c10d3c832aec44ab1ff46e454d5292" }, "downloads": -1, "filename": "python_utilities_jsm-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5752ea1b7a80f0a04aad0fef91f5c33f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 141789, "upload_time": "2019-10-30T17:10:44", "upload_time_iso_8601": "2019-10-30T17:10:44.980072Z", "url": "https://files.pythonhosted.org/packages/97/c3/6a0c1649a8e5200de57d0050d9798ac56520358c93db32e671e6a3d4c617/python_utilities_jsm-1.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "f6b6b35063690cb268271b20f28b3614", "sha256": "7c18c7cf32b9b0afc6059f262c5d0be62afd24de36a8756c3a0f9daf3e06d515" }, "downloads": -1, "filename": "python-utilities-jsm-1.0.1.tar.gz", "has_sig": false, "md5_digest": "f6b6b35063690cb268271b20f28b3614", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 107300, "upload_time": "2019-10-30T17:10:46", "upload_time_iso_8601": "2019-10-30T17:10:46.783883Z", "url": "https://files.pythonhosted.org/packages/35/14/ff00da21be700393b3c938340ad1ba49f98061c479f9bfba30cf4f44a825/python-utilities-jsm-1.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "818304b6f75d77114ecc1b28ff439cec", "sha256": "87a639c12d789cb5c537af0b0fa41dacdfe36e1fb4647d9cad510ffc223af169" }, "downloads": -1, "filename": "python_utilities_jsm-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "818304b6f75d77114ecc1b28ff439cec", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 149092, "upload_time": "2021-04-14T03:11:04", "upload_time_iso_8601": "2021-04-14T03:11:04.787016Z", "url": "https://files.pythonhosted.org/packages/3a/04/b866fae20085712ec0cad766a18b6996f2c095948c5eb06a57dc99e6ade9/python_utilities_jsm-1.0.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "e0ef9f99032ee82368416638b6523e86", "sha256": "533e85a7e12d3940f1781e6da6a2ed1dbce075eeeccb1c98fc060e445ec383c7" }, "downloads": -1, "filename": "python-utilities-jsm-1.0.2.tar.gz", "has_sig": false, "md5_digest": "e0ef9f99032ee82368416638b6523e86", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 117193, "upload_time": "2021-04-14T03:11:05", "upload_time_iso_8601": "2021-04-14T03:11:05.910442Z", "url": "https://files.pythonhosted.org/packages/1d/56/5e4657aec1d08974afe00c9713f40b7035cec0bb104ddbdf434b819538cc/python-utilities-jsm-1.0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "f5bd9ed83373da3fdd9cab911691b299", "sha256": "72da06fa16fb6278451dd0c4e99040ae7b1bc2c87fd12fbe79e5ce48aa5a9993" }, "downloads": -1, "filename": "python_utilities_jsm-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f5bd9ed83373da3fdd9cab911691b299", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 190899, "upload_time": "2022-01-26T05:11:46", "upload_time_iso_8601": "2022-01-26T05:11:46.111852Z", "url": "https://files.pythonhosted.org/packages/e7/a0/ae24b71721be280bc85910e1d0e96809903626cfa1cc09aef16049daa685/python_utilities_jsm-1.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "d27c0f4d79c0b5acd218b039c0116970", "sha256": "b58a7d8d3e6b20c6f77f735d68f19dbf01ae30cc6f1edf84d9e8e42f2e4d1198" }, "downloads": -1, "filename": "python-utilities-jsm-1.1.0.tar.gz", "has_sig": false, "md5_digest": "d27c0f4d79c0b5acd218b039c0116970", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 152255, "upload_time": "2022-01-26T05:11:47", "upload_time_iso_8601": "2022-01-26T05:11:47.649121Z", "url": "https://files.pythonhosted.org/packages/31/6b/3c9f06e8865ed9e4d2bf856aff18567eb10c46e866c346f713015ee3dd00/python-utilities-jsm-1.1.0.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f5bd9ed83373da3fdd9cab911691b299", "sha256": "72da06fa16fb6278451dd0c4e99040ae7b1bc2c87fd12fbe79e5ce48aa5a9993" }, "downloads": -1, "filename": "python_utilities_jsm-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f5bd9ed83373da3fdd9cab911691b299", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 190899, "upload_time": "2022-01-26T05:11:46", "upload_time_iso_8601": "2022-01-26T05:11:46.111852Z", "url": "https://files.pythonhosted.org/packages/e7/a0/ae24b71721be280bc85910e1d0e96809903626cfa1cc09aef16049daa685/python_utilities_jsm-1.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "d27c0f4d79c0b5acd218b039c0116970", "sha256": "b58a7d8d3e6b20c6f77f735d68f19dbf01ae30cc6f1edf84d9e8e42f2e4d1198" }, "downloads": -1, "filename": "python-utilities-jsm-1.1.0.tar.gz", "has_sig": false, "md5_digest": "d27c0f4d79c0b5acd218b039c0116970", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 152255, "upload_time": "2022-01-26T05:11:47", "upload_time_iso_8601": "2022-01-26T05:11:47.649121Z", "url": "https://files.pythonhosted.org/packages/31/6b/3c9f06e8865ed9e4d2bf856aff18567eb10c46e866c346f713015ee3dd00/python-utilities-jsm-1.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }