py-utils

Useful, oft-repeated things for Python

https://github.com/haaksmash/pyutils

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 6 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.8%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Useful, oft-repeated things for Python

Basic Info
  • Host: GitHub
  • Owner: haaksmash
  • License: lgpl-3.0
  • Language: Python
  • Default Branch: master
  • Size: 61.5 KB
Statistics
  • Stars: 25
  • Watchers: 1
  • Forks: 11
  • Open Issues: 2
  • Releases: 0
Created about 13 years ago · Last pushed over 2 years ago
Metadata Files
Readme License

README.rst

Utils
=====

.. image:: https://travis-ci.org/haaksmash/pyutils.svg?branch=master
    :target: https://travis-ci.org/haaksmash/pyutils

Sometimes you write a function over and over again; sometimes you look up at
the ceiling and ask "why, Guido, why isn't this included in the standard
library?"

Well, we perhaps can't answer that question. But we can collect those functions
into a centralized place!

Provided things
+++++++++++++++

Utils is broken up into broad swathes of functionality, to ease the task of
remembering where exactly something lives.

enum
----

Python doesn't have a built-in way to define an enum, so this module provides (what I think) is a pretty clean way to go about them.

.. code-block:: python

    from utils import enum

    class Colors(enum.Enum):
        RED = 0
        GREEN = 1

        # Defining an Enum class allows you to specify a few
        # things about the way it's going to behave.
        class Options:
            frozen = True # can't change attributes
            strict = True # can only compare to itself; i.e., Colors.RED == Animals.COW
                          # will raise an exception.

    # or use the enum factory (no Options, though)
    ColorsAlso = enum.enum("RED", "GREEN")

Once defined, use is straightforward:

.. code-block:: python

    >>> Colors
    
    >>> Colors.RED
    
    >>> Colors.RED == 0
    True
    >>> Colors.RED == Colors.RED
    True
    >>> Colors.RED = 2
    Traceback (most recent call last):
      File "", line 1, in 
      File "utils/enum.py", line 114, in __setattr__
        raise TypeError("can't set attributes on a frozen enum")
    TypeError: can't set attributes on a frozen enum

math
----

Currently only has the multiplicative analogue of the built-in ``sum``.

dicts
-----

intersections, differences, winnowing, a few specialized dicts...

lists
-----

flatten and unlisting. also ``flat_map``!

bools
-----

currently only provides an ``xor`` function.

dates
-----

Mostly cool for the ``TimePeriod`` classes:

.. code-block:: python

    >>> from datetime import date # will also work with datetimes
    >>> time_period = TimePeriod(date(2013, 5, 10), date(2013, 8, 11))
    >>> time_period
    
    >>> date(2013, 6, 12) in time_period
    True
    >>> other_time_period = TimePeriod(date(2013, 6, 1), date(2013, 6, 30))
    >>> other_time_period in time_period
    True
    >>> another_time_period = TimePeriod(date(2013, 8, 1), date(2013, 8, 30))
    >>> time_period.overlaps(another_time_period)
    True
    >>> TimePeriod.get_containing_period(time_period, another_time_period)
    


and so on and so forth. There's also a ``DiscontinousTimePeriod`` class, which
stores a collection of TimePeriods.

There's also helper functions for common operations like ``days_ahead`` and
``days_ago``, which pretty much do what they say on the tin.

objects
-------

provides ``get_attr``, which is really just a convenient way to do deep ``getattr`` chaining:

.. code-block:: python

    >>> get_attr(complicated, 'this.is.a.deep.string', default=None)
    "the deep string"  # or None, if anything in the lookup chain didn't exist

There's also an ``immutable`` utility, which will wrap an object and preven all attribute changes,
recursively by default. Any attempt to set attributes on the wrapped object will raise an ``AttributeError``:

.. code-block:: python

    >>> imm = immutable(something)
    >>> imm
    >
    >>> imm.red
    >
    >>> imm.red = SomethingElse('blue')
    # ...
    AttributeError: This object has been marked as immutable; you cannot set its attributes.
    >>> something.red = SomethingElse('blue')
    >>> imm.red
    >

You can toggle the recursive immutability by specifying the 'recursive' flag.

Installation (via pip)
++++++++++++++++++++++

    pip install utils

Owner

  • Name: Haak Saxberg
  • Login: haaksmash
  • Kind: user

Engineer @tryretool , formerly @Gusto

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 77
  • Total Committers: 6
  • Avg Commits per committer: 12.833
  • Development Distribution Score (DDS): 0.065
Past Year
  • Commits: 3
  • Committers: 2
  • Avg Commits per committer: 1.5
  • Development Distribution Score (DDS): 0.333
Top Committers
Name Email Commits
Haak Saxberg h****g@g****m 72
Akshesh Doshi a****i@g****m 1
Dav Clark d****k@b****u 1
Enrico Hartung e****g@z****e 1
Martin Levy m****n@m****m 1
Karthikeyan Singaravelan t****i@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 12
  • Total pull requests: 19
  • Average time to close issues: 3 months
  • Average time to close pull requests: 2 months
  • Total issue authors: 10
  • Total pull request authors: 8
  • Average comments per issue: 1.42
  • Average comments per pull request: 0.68
  • Merged pull requests: 16
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: 2 days
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • haaksmash (3)
  • kloczek (1)
  • sip0724 (1)
  • anthrax-0 (1)
  • davclark (1)
  • ehartung (1)
  • BrookMakF (1)
  • mahtin (1)
  • rgoalcast (1)
  • Bcopeland64 (1)
Pull Request Authors
  • haaksmash (11)
  • mahtin (2)
  • akki (2)
  • dependabot[bot] (1)
  • ehartung (1)
  • inexxt (1)
  • tirkarthi (1)
  • davclark (1)
Top Labels
Issue Labels
3.8 (1) enhancement (1)
Pull Request Labels
dependencies (1)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 248,535 last-month
  • Total docker downloads: 4,662
  • Total dependent packages: 13
    (may contain duplicates)
  • Total dependent repositories: 943
    (may contain duplicates)
  • Total versions: 14
  • Total maintainers: 2
pypi.org: utils

A grab-bag of utility functions and objects

  • Versions: 12
  • Dependent Packages: 12
  • Dependent Repositories: 943
  • Downloads: 248,535 Last month
  • Docker Downloads: 4,662
Rankings
Dependent repos count: 0.4%
Downloads: 0.5%
Dependent packages count: 1.1%
Docker downloads count: 2.1%
Average: 4.6%
Forks count: 10.9%
Stargazers count: 12.9%
Maintainers (1)
Last synced: 10 months ago
spack.io: py-utils

Useful, oft-repeated things for Python

  • Versions: 2
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 19.3%
Forks count: 24.0%
Stargazers count: 25.1%
Dependent packages count: 28.1%
Maintainers (1)
Last synced: 10 months ago

Dependencies

Pipfile pypi
  • mock ~=1.0 develop
  • pytest ~=5.0 develop
  • tox ~=3.0 develop
Pipfile.lock pypi
  • atomicwrites ==1.3.0 develop
  • attrs ==19.1.0 develop
  • filelock ==3.0.12 develop
  • importlib-metadata ==0.19 develop
  • mock ==1.3.0 develop
  • more-itertools ==7.2.0 develop
  • packaging ==19.1 develop
  • pbr ==5.4.2 develop
  • pluggy ==0.12.0 develop
  • py ==1.8.0 develop
  • pyparsing ==2.4.2 develop
  • pytest ==5.0.1 develop
  • six ==1.12.0 develop
  • toml ==0.10.0 develop
  • tox ==3.13.2 develop
  • virtualenv ==16.7.2 develop
  • wcwidth ==0.1.7 develop
  • zipp ==0.5.2 develop
setup.py pypi