Skip to main content

snippyts

Miscellaneous utility scripts and Python objects for agile development.

  1. Table of objects
  2. Change log
  3. Instructions for running tests

Table of objects

No. Name Description Date added Date reviewed
1 snippyts.
__init__.
batched
Partitions an input collection iterable into chunks of size batch_size. The number of chunks is unknown at the time of calling is determined by the length of iterable. 2024 Sep 22 2024 Sep 22
2 snippyts.
__init__.
flatten
Given a collection of lists, concatenates all elements into a single list. More formally, given a collection holding n iterables with m elements each, this function will return a single list holding all n * m elements. 2024 Sep 22 2024 Sep 22
3 create_python_
simple_package.sh
BASH script to initialize a local Python package as a local git repository with a virtual environment, project files, and standard folder structure. It takes user input into account for parameterization from the command line. 2024 Sep 22 2024 Sep 23
4 snippyts.
__init__.
to_txt
Function that expects two string parameters as arguments and writes the first string as the content of a file at the location denoted by the second string (which is assumed to denote a POSIX path). 2024 Sep 23 2024 Sep 23
5 snippyts.
__init__.
from_txt
Function that can be directed to a local raw text file by its POSIX path and returns the content of that file as a string. 2024 Sep 23 2024 Sep 23
6 snippyts.
__init__.
to_json
Function that expects two parameters as arguments, a Python dictionary and a string, and writes the former as the content of a file at the location denoted by the latter (which is assumed to denote a POSIX path). 2024 Sep 24 2024 Sep 24
7 snippyts.
__init__.
from_json
Function that can be directed to a local JSON file by its POSIX path and returns the content of that file as a Python dictionary. 2024 Sep 24 2024 Sep 24
8 snippyts.
__init__.
to_pickle
Function that can be directed to a local raw text file by its POSIX path and returns the content of that file as a Python dictionary. 2024 Oct 03 2024 Oct 03
9 snippyts.
__init__.
from_pickle
Function that can be directed to a local Python-pickle file by its POSIX path and returns a copy of the artifact persisted in that file. 2024 Oct 03 2024 Oct 03
10 snippyts.trie.Trie A class implementing a trie data structure. 2024 Oct 03 2025 Aug 27
11 snippyts.
vocabulary_tools.
ExactStringMatcher
A wrapper around flashtext2 providing a unified application interface shared with FuzzySet. 2024 Oct 12 2024 Oct 26
12 snippyts.
vocabulary_tools.
FuzzyStringMatcher
A wrapper around FuzzySet providing a unified application interface shared with flashtext2. 2024 Oct 13 2024 Oct 26
13 snippyts.
__init__.
to_csv
Function that expects two parameters as arguments, a list of lists (or, more geneally, an Iterable contaning other Iterables which is expected to represent a CSV-structured matrix) and a string, and writes the former as the content of a file at the location denoted by the latter (which is assumed to denote a POSIX path). 2024 Oct 26 2024 Oct 26
14 snippyts.
__init__.
from_csv
Function that can be directed to a local CSV file by its POSIX path and returns the content of that file as a list of lists (or, more geneally, an Iterable contaning other Iterables which is expected to represent a CSV-structured matrix). 2024 Oct 26 2024 Oct 26
15 snippyts.
__init__.
tryline
Wraps a try-raise block into a single statement. It is intended to flatten try-catch.

It attempts to call the specified Python-callable object with the provided arguments and keyword arguments.

If the call is successful, it silently returns the output of the call.

If it fails, it raises an exception of the type provided as the second argument.
2025 Feb 28 2025 Feb 28
16 snippyts.
__init__.
is_url
Determines whether a given string is a valid URL.

It uses urllib.parse.urlparse, a function that splits a URL into six components: scheme, network location, path, parameters, query, and fragment.
2025 Feb 28 2025 Feb 28
18 snippyts.
preprocessing.
KBinsEncoder
Discretizes the data into n_bins using scikit-learn's KBinsDiscretizer class, and then replaces every input value with the value at the bin-th quantile, ensuring that the output vector
- only has n_bins unique element but
- has the same dimensionality as the original input vector.
2025 Feb 28 2025 Aug 23
19 snippyts.
__init__.
to_yaml
Works like to_txt but writes out YAML-formatted data. 2025 Jul 27 2025 Jul 27
20 snippyts.
__init__.
cp
Shorthand for copy.deepcopy. 2025 Jul 27 2025 Jul 27
21 snippyts.
__init__.
from_yaml
Works like from_yaml but reads in YAML-formatted data into a Python dictionary object. 2025 Jul 27 2025 Jul 27
22 snippyts.
__init__.
defolder
Function that takes a path string as an argument. If a folder at that path does not exist yet, it gets created. It then returns the real path of the folder, resolving any symbolic links in the path if they exist. File names are implicitly parsed for their containing folder names; the folder name is handled as per the specifications but the final path returned by the function will include again the file name. 2025 Jul 27 2025 Jul 27
23 snippyts.
metrics.
average_token_similarity
Given two strings, it greedily and fuzzily aligns their tokens by similarity and returns the similarity ratio for the full sequence averaged over all tokens. 2025 Jul 28 2025 Jul 28
24 snippyts.
__init__.
UnsupportedInputShapeError
Self-explanatory exception. 2025 AUG 1 2025 AUG 1
25 snippyts.
__init__.
smart_cast_number
Cast a numeric value to an integer if it is numerically whole; otherwise, return as float. 2025 AUG 1 2025 AUG 1
26 snippyts.
__init__.
is_number
Function that checks whether a string can be interpreted as a integer or a float. 2025 AUG 1 2025 AUG 1
27 snippyts.
__init__.
read_arg
Function that reads command line arguments passed to a python script, then returns the corresponding value of the specified argument's name. 2025 JUL 27 2025 JUL 27
28 snippyts.
__init__.
read_args
Function that reads all named command line arguments passed to a Python script (names are those starting with - or --), then saves their corresponding values into a namedtuple.

The argument names are converted into valid attribute names by stripping leading hyphens and replacing non-alpha-numeric characters with underscores.
2025 JUL 27 2025 JUL 27
29 snippyts.
cachionary.
Cachionary
A class implementing a caching dictionary that persists data to disk in JSON or pickle format. On initialization, it loads existing data from the given file path; on program exit (via atexit), it serializes the dictionary back to disk. Supports standard dictionary operations (in, [] access, assignment). 2026 APR 09 2026 APR 09
30 snippyts.
__init__.
is_nothing
Verifies that the input expresses no useful information or conveys zero actual information. This is defined as: an empty string, a zero value, a null string, a numpy.NaN value, an empty list, an empty set, an empty dictionary, or a Boolean value. 2026 JUL 30 2026 JUL 30
31 snippyts.
__init__.
timestamp
Returns a standard-format string denoting a specific time: YYYYMMDD or YYYYMMDD_HHMMSS. Defaults to execution time but can be set through the when parameter. 2026 JUL 30 2026 JUL 30
32 snippyts.
__init__.
stripstring
Returns a cleaned copy of the input string. The input is lowercased, Unicode-decoded into ASCII, stripped of leading and trailing non-alphanumeric characters, with remaining non-alphanumeric characters replaced by a single whitespace and sequences of two or more adjacent whitespaces collapsed into one. Each step can be toggled via its corresponding boolean parameter. 2026 JUL 30 2026 JUL 30
33 snippyts.
preprocessing.
Text
A class providing class methods for natural language preprocessing using NLTK. Given a string (or a list of strings, each treated as a full document), Text.tokens splits it into tokens, Text.words keeps only the alphabetic tokens (optionally padding the rest with #), and Text.sentences splits it into sentences. 2026 AUG 10 2026 AUG 10

Deprecated

No. Name Description Date added Date removed
17 snippyts.
__init__.
gtml
Removed due to authentication issues. Nowadays, most websites seem to be rejecting connections with the kind of parameterization used in this function. Gets the HTML content of the document at the specified location URL. Named gtml as a shorthand for "get HTML". 2025 Feb 28 2025 Nov 22

Change log

2026 AUG

Functions

  1. Adds snippyts.__init__.is_nothing, a function that verifies whether an input expresses no useful information (empty strings/collections, zero, None, NaN, or Boolean values).
  2. Adds snippyts.__init__.timestamp, a function returning a standard-format timestamp string (YYYYMMDD or YYYYMMDD_HHMMSS), defaulting to execution time.
  3. Adds snippyts.__init__.stripstring, a function that cleans an input string via lowercasing, ASCII transliteration, non-alphanumeric stripping, blank collapsing, and whitespace collapsing.

Text Preprocessing

  1. Adds snippyts.preprocessing.Text, a class with class methods for tokenizing, word-extracting, and sentence-splitting strings (or collections of strings) using NLTK.

Documentation

  1. Adds docstrings to all functions.

Testing

  1. Adds tests for new features.
  2. Fixes failures in obsolete tests.

Fixes

  1. Returns null instead of raising an exception.
  2. Cleans up code.

2026 APR

Caching & Persistence

  1. Adds snippyts.cachionary.Cachionary, a class implementing a caching dictionary with automatic disk persistence (JSON or pickle format) and atexit-based serialization.

2025 NOV

Networking

  1. Removed gtml function for scraping as most sites tend to block it and ends up not working unless more advanced authentication is implemented.

NLP & ML

  1. Fixes snippyts.trie.Trie.
  2. Fixes snippyts.preprocessing.KBinsEncoder.
  3. Adds snippyts.metrics.average_token_similarity, a function for calculating the average token similarity between two strings.

I/O Functions

  1. Adds snippyts.__init__.to_yaml, a function for writing out YAML-formatted data.
  2. Adds snippyts.__init__.from_yaml, a function that reads in YAML-formatted data into a Python dictionary.
  3. Adds snippyts.__init__.read_arg, a function that returns the value of a specified command-line parameter name (names are those starting with - or --).
  4. Adds snippyts.__init__.read_args, like read_arg but for applies implicitly to all parameters and returns their arguments as values in a namedtuple, with the parameter name as the attributes.

System & Language

  1. Adds snippyts.__init__.cp, a shorthand for copy.deepcopy.
  2. Adds snippyts.__init__.smart_cast_number, a function for casting a numeric value to an integer if it is numerically whole; otherwise, return as float.
  3. Adds snippyts.__init__.is_number, a function that checks whether a string can be interpreted as a integer or a float.
  4. Adds snippyts.__init__.defolder, a function that handles path strings and creates folders if they do not exist yet.
  5. Adds snippyts.__init__.UnsupportedInputShapeError, an exception for handling unsupported input shapes.

Running tests

Using pytest

Change into the project's home folder (first line below) and run pytest (second line). After moving into that directory, the working folder should contain two subfolders, src (in turn the parent of subfolder snippyts) and tests:

cd snippyts ;
pytest tests ;

Running the module as a package

cd snippyts ;
python -m src.snippyts.__init__ ;
python -m src.snippyts.preprocessing ;

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snippyts-0.3.4.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

snippyts-0.3.4-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file snippyts-0.3.4.tar.gz.

File metadata

  • Download URL: snippyts-0.3.4.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for snippyts-0.3.4.tar.gz
Algorithm Hash digest
SHA256 fed99e1cb5b991839de7d68f9e316555708f725bd9c9ca5e9c08171704fe88da
MD5 6d18d86b17ec7ee7abd910f102b1bea0
BLAKE2b-256 4d5d1d1332ccebee76048c370d3f83fe49ba775acc82c349a79e53a8f1aacc96

See more details on using hashes here.

File details

Details for the file snippyts-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: snippyts-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for snippyts-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6554839b6fccf0c0ffec0e1abaeac72be18c14be3db8cb14bc54a23df8b8a2c4
MD5 994cc0d625eaf489619a066fe9a1c0e0
BLAKE2b-256 8f68c59d534d8281c8be1e74e0c5f38630d0d28c40f897b552f76042d10cbb87

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

0.0.7

2 files

0.0.6

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page