datasize


Namedatasize JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/aphor/datasize
SummaryPython integer subclass to handle arithmetic and formatting of integers with data size units
upload_time2020-11-28 23:44:57
maintainer
docs_urlNone
authorJeremy McMillan
requires_python
license
keywords data units parser formatter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            [![Build Status](https://travis-ci.org/aphor/datasize.svg?branch=master)](https://travis-ci.org/aphor/datasize) [![Coverage Status](https://coveralls.io/repos/aphor/datasize/badge.svg?branch=master)](https://coveralls.io/r/aphor/datasize?branch=master) 
# DataSize
Python integer subclass to handle arithmetic and formatting of integers with data size units

Provides parsing, arithmetic and comparison oprations, and formatting of human readable data size strings for logic that depends on comparisons of values given in common units of data allocation. There are other solutions, but they are either not complete, or too heavy or awkward for casual use. A string like "14GiB" is really an integer representing a data allocation.

The basic use case is to be able to parse a string containing a common expression of data size with a numeric value and a unit of data. The resulting object is actually an integer count of bytes, so that it can be used in any arithmetic expression. That integer can be expressed, using Python 3 string formatting, as any other unit of data. This allows, for example, configuration files that support a natural way of expressing and operating on quantities of data.

DataSize supports metric and IEC units in both bits and bytes and nonstandard abbreviated IEC units (for legacy Java -Xmx). There is support for variable word-lengths, but because I thought it would get confusing, converting between two different word lengths is not supported. The word length constructor keyword argument will allow converting counts of weird (actually non-byte) word or symbol bit lengths to bit rates, which can then be explicitly converted to standard 8-bit bytes.

The really sweet feature that everyone should love is the Python string.format() support!
```
Help on method __format__ in module datasize.DataSize:

__format__(self, code) unbound datasize.__datasize__.DataSize method
    formats as a decimal number, but recognizes data units as type format codes.
    Precision is ignored for integer multiples of the unit specified in the format code.
    format codes:  
    a    autoformat will choose a unit defaulting to the largest
          size with a quantity >= 1 (default)
    A    abbreviated number of bytes (implied IEC units, and implied 'B' bytes suffix omitted)
    B    bytes      (1)
    kiB  kibibytes  (1024)
    kB   kilobytes  (1000)
    ...
    GiB  Gibibytes  (1024**3)
    GB   Gigabytes  (10**9)
    ...
    YiB  Yobibytes  (1024**8)
    YB   Yottabytes (10**24)
```
```
>>> from datasize import DataSize
>>> 'My new {:GB} SSD really only stores {:.2GiB} of data.'.format(DataSize('750GB'),DataSize(DataSize('750GB') * 0.8))
'My new 750GB SSD really only stores 558.79GiB of data.'
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aphor/datasize",
    "name": "datasize",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "data,units,parser,formatter",
    "author": "Jeremy McMillan",
    "author_email": "jeremy.mcmillan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/91/32/2e3a423003fb9b8fe703641ff0f33197caba606ae5cd6cc4ae380e892487/datasize-1.0.0.tar.gz",
    "platform": "",
    "description": "[![Build Status](https://travis-ci.org/aphor/datasize.svg?branch=master)](https://travis-ci.org/aphor/datasize) [![Coverage Status](https://coveralls.io/repos/aphor/datasize/badge.svg?branch=master)](https://coveralls.io/r/aphor/datasize?branch=master) \n# DataSize\nPython integer subclass to handle arithmetic and formatting of integers with data size units\n\nProvides parsing, arithmetic and comparison oprations, and formatting of human readable data size strings for logic that depends on comparisons of values given in common units of data allocation. There are other solutions, but they are either not complete, or too heavy or awkward for casual use. A string like \"14GiB\" is really an integer representing a data allocation.\n\nThe basic use case is to be able to parse a string containing a common expression of data size with a numeric value and a unit of data. The resulting object is actually an integer count of bytes, so that it can be used in any arithmetic expression. That integer can be expressed, using Python 3 string formatting, as any other unit of data. This allows, for example, configuration files that support a natural way of expressing and operating on quantities of data.\n\nDataSize supports metric and IEC units in both bits and bytes and nonstandard abbreviated IEC units (for legacy Java -Xmx). There is support for variable word-lengths, but because I thought it would get confusing, converting between two different word lengths is not supported. The word length constructor keyword argument will allow converting counts of weird (actually non-byte) word or symbol bit lengths to bit rates, which can then be explicitly converted to standard 8-bit bytes.\n\nThe really sweet feature that everyone should love is the Python string.format() support!\n```\nHelp on method __format__ in module datasize.DataSize:\n\n__format__(self, code) unbound datasize.__datasize__.DataSize method\n    formats as a decimal number, but recognizes data units as type format codes.\n    Precision is ignored for integer multiples of the unit specified in the format code.\n    format codes:  \n    a    autoformat will choose a unit defaulting to the largest\n          size with a quantity >= 1 (default)\n    A    abbreviated number of bytes (implied IEC units, and implied 'B' bytes suffix omitted)\n    B    bytes      (1)\n    kiB  kibibytes  (1024)\n    kB   kilobytes  (1000)\n    ...\n    GiB  Gibibytes  (1024**3)\n    GB   Gigabytes  (10**9)\n    ...\n    YiB  Yobibytes  (1024**8)\n    YB   Yottabytes (10**24)\n```\n```\n>>> from datasize import DataSize\n>>> 'My new {:GB} SSD really only stores {:.2GiB} of data.'.format(DataSize('750GB'),DataSize(DataSize('750GB') * 0.8))\n'My new 750GB SSD really only stores 558.79GiB of data.'\n```",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python integer subclass to handle arithmetic and formatting of integers with data size units",
    "version": "1.0.0",
    "split_keywords": [
        "data",
        "units",
        "parser",
        "formatter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "c9a89ec1f22fb979978794dd23af583c",
                "sha256": "57a6fee8f438221fb2ba36d5851f4f2eb9677b5378477c00e32b2d6700122478"
            },
            "downloads": -1,
            "filename": "datasize-1.0.0.tar.gz",
            "has_sig": true,
            "md5_digest": "c9a89ec1f22fb979978794dd23af583c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 149444,
            "upload_time": "2020-11-28T23:44:57",
            "upload_time_iso_8601": "2020-11-28T23:44:57.286066Z",
            "url": "https://files.pythonhosted.org/packages/91/32/2e3a423003fb9b8fe703641ff0f33197caba606ae5cd6cc4ae380e892487/datasize-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-11-28 23:44:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "aphor",
    "github_project": "datasize",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "lcname": "datasize"
}
        
Elapsed time: 0.17717s