Skip to main content

130+ extra higher-level functional tools beyond standard and third-Party libraries.

Project description

PyPI version PyPI pyversions PyPI license

Featured on GitHub's Trending Python repos on May 25, 2018. Thank you so much for support!

130+ extra higher-level functional tools that go beyond standard library's itertools, functools, etc. and popular third-party libraries like toolz, fancy, and more-itertools.

  • Like toolz and others, most of the tools are designed to be efficient, pure, and lazy. Several useful yet non-functional tools are also included.

  • While toolz and others target basic scenarios, this library targets more advanced and higher-level scenarios.

  • A few useful CLI tools for respective functions are also installed. They are available as extratools-[func].

Full documentation is available here.

Current Progress and Future Plans

There are currently 120+ functions among 14 categories, 3 data structures, and 3 CLI tools.

This library is under active development, and new tools are added on weekly basis.

  • Any idea or contribution is highly welcome.

Besides many other interesting ideas, I am planning to make the following updates in recent days/weeks/months.

  • Add dicttools.unflatten and jsontools.unflatten.

  • Add trie and suffixtree (according to generalized suffix tree).

  • Update seqtools.commonsubseq, seqtools.commonsubseqwithgap, seqtools.align, and strtools.commonsubstr to support more than two sequences/strings.

Index of Available Tools

Examples

Here are a few examples out of hundreds of our tools.

from extratools.seqtools import compress

list(compress([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]))
# [(1, 1), (2, 2), (3, 3), (4, 4)]
from math import inf
from extratools.rangetools import gaps

list(gaps(
    [(-inf, 0), (0.1, 0.2), (0.5, 0.7), (0.6, 0.9)],
    (0, 1)
))
# [(0, 0.1), (0.2, 0.5), (0.9, 1)]
import json
from extratools.jsontools import flatten

flatten(json.loads("""{
  "name": "John",
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}"""))
# {'name': 'John',
#  'address.streetAddress': '21 2nd Street',
#  'address.city': 'New York',
#  'phoneNumbers[0].type': 'home',
#  'phoneNumbers[0].number': '212 555-1234',
#  'phoneNumbers[1].type': 'office',
#  'phoneNumbers[1].number': '646 555-4567',
#  'children': [],
#  'spouse': None}

strtools.learnrewrite(src, dst, minlen=3) learns the respective regular expression and template to rewrite src to dst.

from extratools.strtools import learnrewrite

learnrewrite(
    "Elisa likes icecream.",
    "icecream is Elisa's favorite."
)
# ('(.*) likes (.*).',
#  "{1} is {0}'s favorite.")

tabletools.parsebymarkdown(text) parses a text of multiple lines to a table, according to Markdown format.

from extratools.tabletools import parsebymarkdown

list(parsebymarkdown("""
| foo | bar |
| --- | --- |
| baz | bim |
"""))
# [['foo', 'bar'],
#  ['baz', 'bim']]

Installation

This package is available on PyPI. Just use pip3 install -U extratools to install it.

Recommended Libraries

Libraries recommended to use with extratools: regex sortedcontainers toolz

Reference

When using for research purpose, please cite this library as follows.

@misc{extratools,
  author = {Chuancong Gao},
  title = {{extratools}},
  howpublished = "\url{https://github.com/chuanconggao/extratools}",
  year = {2018}
}

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

extratools-0.7.tar.gz (17.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page