Package: sizeof
Simple function for determining the memory usage of common Python values and objects.Installation and UsageThis library is available as apackage on PyPI:python-mpipinstallsizeofThe library can be imported in the usual ways:importsizeoffromsizeofimportsizeofExamplesThesizeoffunction can be applied to any value or object. By default, the function returns the memory consumed by that value or object (andnotby any of the objects to which it may contain references):>>>fromsizeofimportsizeof>>>sizeof(123.0123)16The amount of memory consumed for any given value or object is in part determined by the host architecture and the version of Python being used. Thearchfunction can be used to determine whether the architecture is 32-bit or 64-bit:>>>fromsizeofimportarch>>>arch()32The optionaldeepargument of thesizeoffunction makes it possible to calculate the memory consumed by an object and all of it descendants by reference:>>>sizeof([])# Size of an empty list.28>>>sizeof([1]),sizeof([1,2])# Size of reference is 4.(32,36)>>>sizeof(3)# Size of an integer.14>>>sizeof([1,2,3])==28+(3*4)True>>>sizeof([1,2,3],deep=True)==28+(3*(4+14))TrueNote that all of the examples above may return different results on your system and in your environment.DevelopmentAll installation and development dependencies are fully specified inpyproject.toml. Theproject.optional-dependenciesobject is used tospecify optional requirementsfor various development tasks. This makes it possible to specify additional options (such asdocs,lint, and so on) when performing installation usingpip:python-mpipinstall.[docs,lint]DocumentationThe documentation can be generated automatically from the source files usingSphinx:python-mpipinstall.[docs]cddocssphinx-apidoc-f-E--templatedir=_templates-o_source..&&makehtmlTesting and ConventionsAll unit tests are executed and their coverage is measured when usingpytest(see thepyproject.tomlfile for configuration details):python-mpipinstall.[test]python-mpytestAlternatively, all unit tests are included in the module itself and can be executed usingdoctest:pythonsrc/sizeof/sizeof.py-vStyle conventions are enforced usingPylint:python-mpipinstall.[lint]python-mpylintsrc/sizeofContributionsIn order to contribute to the source code, open an issue or submit a pull request on theGitHub pagefor this library.VersioningThe version number format for this library and the changes to the library associated with version number increments conform withSemantic Versioning 2.0.0.PublishingThis library can be published as apackage on PyPIby a package maintainer. First, install the dependencies required for packaging and publishing:python-mpipinstall.[publish]Ensure that the correct version number appears inpyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has anautomation rulethat activates and sets as the default all tagged versions. Create and push a tag for this version (replacing?.?.?with the version number):gittag?.?.?gitpushorigin?.?.?Remove any old build/distribution files. Then, package the source into a distribution archive:rm-rfbuilddistsrc/*.egg-infopython-mbuild--sdist--wheel.Finally, upload the package distribution archive toPyPI:python-mtwineuploaddist/*