Skip to main content

Makes Python simpler.

Project description

Simpler

A library to make Python even simpler.

It contains an assorted selection of utils that I use on my projects.

Installation

It is available in PyPI, just do pip install simpler.

Usage

Every method is properly documented. To use it, just do from simpler import ... and see all the choices that you have.

  • simpler.files
    • cwd: changes working directory, base of relative routes, to the one where the script is located.
    • read: simplified read of a file with a single interface for string, bytes, json and pickle files.
    • write: simplified write to a file with the same format as read.
    • disk_cache: this @annotation caches a file in the disk.
    • size: given a file, returns its size without loading it to memory.
    • find_hidden_compressed: given a file, finds if it contains the signature for any compressed format.
    • tvshow_rename: rename every TV show of a folder.
    • directory_compare: compares the changes in two directories recursively.
  • simpler.format
    • human_bytes: transforms a size in bytes to a friendly amount.
    • human_seconds: transforms a number of seconds to a friendly format.
    • human_date: transforms a datetime to a relative friendly format.
    • random_string: returns a random string.
    • print_matrix: pretty-prints a 2D-array.
    • safe_filename: given a string name, returns its safe-to-save version.
  • profiling
    • tic: adds the current time to a time stack.
    • toc: pops the last added time from a time stack and prints the difference. Can be used with tic to profile methods.
    • deep_size: recursively approximates the memory size of an object.
  • simpler.math
    • clamp: returns a value clamped in an interval.
    • snap: returns a value snapped to a scale of a given size and offset.
    • unique: given a list, returns a list in the same order excluding repeated elements according to a uniqueness function.
    • all_equal: checks if every element of a sequence is the same.
    • jaccard: returns the Jaccard index of two sequences.
    • levenshtein: Returns the Levenshtein distance of two sequences.
    • base_change: changes the base of a number represented as a list of integers.
    • prime_list: returns the list of prime numbers from 2 to n.
    • is_prime: checks if a number is prime.
    • fibonacci: returns the n-th fibonacci number.
    • lcm: least common multiple of two numbers.
    • gcd: greatest common divisor of two numbers.
    • factor: returns the factors of a number and its exponents.
    • palindrome_list: returns every palindromic number with k digits.
    • phi: Euler's phi function.
  • validation
    • assert_set: asserts that a given value exists and returns it.
    • assert_str: asserts that a given value is a string and complies with some customisable checks, and returns it.
    • assert_number: asserts that a given value is a number and complies with some customisable checks, and returns it.
    • assert_id: asserts that a given value is a valid daabase id and returns it.
    • assert_mail: asserts that a given string is a valid mail and returns it.
    • assert_exists: asserts that the given path exists and returns it.
  • simpler.bioinformatics
    • codon_table: dictionary of codon translations.
    • monoisotopic_mass_table: monoisotopic mass for every amino acid.
    • monoisotopic_mass_water: just that.
    • parse_fasta: given a fasta string, it returns every (or just the first) sequence found.
    • dna_to_rna: given a DNA string, returns its RNA version.
    • rna_to_dna: given a RNA string, returns its DNA version.
    • rna_to_protein: given a RNA string, returns its proteins.
    • reverse_complement: returns the reverse complement of a sequence, either DNA or RNA.
  • simpler.algorithms
    • DynamicProgramming: abstract dynamic programming class. After implementing methods .alternatives(state), .is_final(state) and .penalty(state) you can run .solve, asking for one solution, one optimal solution, every solution or every optimal solution.
  • simpler.databases
    • MySQL: easy way to connect to a MySQL database and forget about implementation stuff. Methods find_many and find_one methods return {col_name: value} dictionaries, find column returns just one value, insert returns the id of the inserted element, and apply returns the row count of deleted/updated rows.
    • Excel: simple connector to an Excel file to retrieve cell ranges using the Excel range format.
  • simpler.mail
    • compose: simplified interface to compose a mail message.
    • send: simplified interface to send a mail.
  • simpler.sparql
    • dbpedia: sends a query to DBPedia.
    • entity_types: returns every entity type with values that contain a given string.
  • terminal
    • getch: reads a sngle byte from the user input.
  • web
    • download_file: stream a download a file from a URL while displaying the progress and ETA.
    • DownloaderPool: pool of workers that download a set of URLs simultaneously.

Project details


Release history Release notifications | RSS feed

This version

1.0.1

Download files

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

Source Distribution

simpler-1.0.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

simpler-1.0.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file simpler-1.0.1.tar.gz.

File metadata

  • Download URL: simpler-1.0.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for simpler-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c1e8e103e40526a910fe0ee017d7062ecb310b03548044d373a83cdbb01aebc2
MD5 821cb3aabdcb783f2e39316337ac384f
BLAKE2b-256 0e4ca06f5494fb5ad811e6be84523ad2fed3e97961a3598c5a77dd2ab84ae114

See more details on using hashes here.

File details

Details for the file simpler-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: simpler-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for simpler-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c2e941f71813e64b8ff128b49c9ddc682a9c2a8ce185468d4416aad60d02aaf
MD5 5d101e96d0bd8793e8f11c824019d5c8
BLAKE2b-256 2ac8baee332b50e3a79dfc2b68d32029729159d21bd4bdbfcece95c0dcdae732

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