pyutils-alexhenderson

Various Python utilities that may be useful

https://github.com/alexhenderson/pyutils

Science Score: 54.0%

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

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

Repository

Various Python utilities that may be useful

Basic Info
  • Host: GitHub
  • Owner: AlexHenderson
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 14.6 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • Open Issues: 1
  • Releases: 3
Created about 4 years ago · Last pushed over 3 years ago
Metadata Files
Readme License Citation

README.md

pyutils

Various Python utilities

Requires Python 3.7 or higher.
Other requirements are listed per utility.

pip install pyutils-AlexHenderson==1.1.1

Utilities

  • unit_manager
  • jsonpintencoder
  • jsondatetimeencoder
  • multiplejsonencoders

pintutils/unitmanager

Requirements

pint

Details

This is a wrapper around the Pint unit management system (https://pint.readthedocs.io/en/stable/). Formats a quantity label suitable for use on the x-axis of a chart. Units are output in their shortform (nm for nanometer). If a unit is not provided, the quantity will be treated as dimensionless.

Example for a wavelength of 280 nm:

    >>> from pyutils.pint_utils import unit_manager
    >>> ureg = unit_manager.pint.UnitRegistry()
    >>> output = unit_manager.unit_manager('wavelength', ureg.nanometer, 280)
    >>> output
    {'name': 'wavelength', 'unit': 'nm', 'label': 'wavelength (nm)', 'value': 280, 'quantity': '280 nm'}
    >>> print(output['label'])
    wavelength (nm)
    >>> print(f'peak position = {output["quantity"]}')
    peak position = 280 nm

Example for unitless absorbance:

    >>> from pyutils.pint_utils import unit_manager
    >>> ureg = unit_manager.pint.UnitRegistry()
    >>> output = unit_manager.unit_manager('absorbance')
    >>> output
    {'name': 'absorbance', 'unit': '', 'label': 'absorbance'}
    >>> print(output['label'])
    absorbance

pintutils/jsonpint_encoder

Requirements

pint

Details

JSON can only encode certain variable types as output. Variables from the Pint unit management system (https://pint.readthedocs.io/en/stable/) are not handled automatically. This code converts a Pint unit to a string, and passes that to the JSON encoding function.

Example:

>>> from pint import Quantity, Unit, UnitRegistry
>>> from pyutils.pint_utils.json_pint_encoder import json_pint_encoder

>>> ureg = UnitRegistry()
>>> duration = Quantity(5.6, ureg.sec)

>>> encoder = json_pint_encoder
>>> jsonoutput = json.dumps(duration, cls=encoder)
>>> print(jsonoutput)
"5.6 second"

datetimeutils/jsondatetime_encoder

Details

JSON can only encode certain variable types as output. datetime variables are not handled automatically. This code converts a datetime variable into its isoformat string (ISO 8601), and passes that to the JSON encoding function.

Example:

>>> import datetime
>>> import json

>>> from pyutils.datetime_utils.json_datetime_encoder import json_datetime_encoder

>>> example = datetime.datetime(2000, 12, 25, 13, 23)

>>> encoder = json_datetime_encoder
>>> jsonoutput = json.dumps(example, cls=encoder)
>>> print(jsonoutput)
"2000-12-25T13:23:00"

multiplejsonencoders

Details

JSON can only encode certain variable types as output. We can supply our own encoder to convert a variable into a format the JSON engine can work with. However, there are occasions when we need to manage more than one type of variable. This class takes multiple encoders and dispatches each variable to its own encoder, before forwarding the output to the JSON engine. The order the encoders are listed as arguments to the multiple_encoders constructor, is the order in which they are evaluated.

Example:

>>> import datetime 
>>> import json

>>> from pint import Quantity, Unit, UnitRegistry

>>> from pyutils.json_utils.multiple_json_encoders import multiple_json_encoders
>>> from pyutils.pint_utils.json_pint_encoder import json_pint_encoder
>>> from pyutils.datetime_utils.json_datetime_encoder import json_datetime_encoder

>>> christmas_time = datetime.datetime(2000, 12, 25, 13, 23)
>>> ureg = UnitRegistry()
>>> duration = Quantity(5.6, ureg.sec)

>>> encoder = multiple_json_encoders(json_pint_encoder, json_datetime_encoder)

>>> christmas_time_output = json.dumps(christmas_time, cls=encoder)
>>> print(christmas_time_output)
"2000-12-25T13:23:00"

>>> durationoutput = json.dumps(duration, cls=encoder)
>>> print(durationoutput)
"5.6 second"

Usage rights

Copyright (c) 2021-2022 Alex Henderson (alex.henderson@manchester.ac.uk)
Licensed under the MIT License. See https://opensource.org/licenses/MIT
SPDX-License-Identifier: MIT
Version 1.1.1
See https://github.com/AlexHenderson/pyutils/ for the most recent version

Owner

  • Name: Alex Henderson
  • Login: AlexHenderson
  • Kind: user
  • Location: Manchester, UK
  • Company: University of Manchester

See also https://bitbucket.org/AlexHenderson/ and https://gist.github.com/AlexHenderson

Citation (CITATION.cff)

cff-version: 1.2.0
message: If you use this software, please cite it using these metadata.
title: pyutils
abstract: Python package with a range of utilities.
authors:
  - family-names: Henderson
    given-names: Alex
    orcid: "https://orcid.org/0000-0002-5791-8555"
    affiliation: University of Manchester, UK
    email: alex.henderson@manchester.ac.uk
    website: https://alexhenderson.info
version: v1.1.1
date-released: "2022-03-07"
license: MIT
license-url: https://spdx.org/licenses/MIT#licenseText
repository: "https://github.com/AlexHenderson/pyutils/"

GitHub Events

Total
Last Year

Committers

Last synced: about 3 years ago

All Time
  • Total Commits: 9
  • Total Committers: 2
  • Avg Commits per committer: 4.5
  • Development Distribution Score (DDS): 0.111
Top Committers
Name Email Commits
Alex Henderson a****n@m****k 8
Alex Henderson a****r@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • RuthStoney (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 5 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 2
  • Total maintainers: 1
pypi.org: pyutils-alexhenderson

Various python utilities

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 5 Last month
Rankings
Dependent packages count: 10.1%
Dependent repos count: 21.6%
Forks count: 22.6%
Average: 28.4%
Stargazers count: 38.8%
Downloads: 48.9%
Maintainers (1)
Last synced: 8 months ago

Dependencies

requirements.txt pypi
  • Pint *
setup.py pypi
  • pint *