{"id":34024034,"url":"https://github.com/anviks/utils-anviks","last_synced_at":"2026-03-17T20:14:37.181Z","repository":{"id":222994098,"uuid":"758225360","full_name":"anviks/utils-anviks","owner":"anviks","description":"Useful decorators and functions for everyday Python programming.","archived":false,"fork":false,"pushed_at":"2025-10-12T22:36:56.000Z","size":115,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-15T05:29:57.698Z","etag":null,"topics":["advent-of-code","aoc","decorators","pip","pypi","pypi-package","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anviks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-02-15T21:42:49.000Z","updated_at":"2025-10-12T22:34:57.000Z","dependencies_parsed_at":"2024-06-19T05:58:32.323Z","dependency_job_id":"eacacdac-8c31-4f92-ab53-d19ab9fb2533","html_url":"https://github.com/anviks/utils-anviks","commit_stats":null,"previous_names":["anviks/utility_package"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/anviks/utils-anviks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anviks%2Futils-anviks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anviks%2Futils-anviks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anviks%2Futils-anviks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anviks%2Futils-anviks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anviks","download_url":"https://codeload.github.com/anviks/utils-anviks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anviks%2Futils-anviks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30630351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advent-of-code","aoc","decorators","pip","pypi","pypi-package","python"],"created_at":"2025-12-13T16:04:15.568Z","updated_at":"2026-03-17T20:14:37.176Z","avatar_url":"https://github.com/anviks.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# utils-anviks\n\nUseful decorators and functions for everyday Python programming.\n\n## Features:\n### Decorators:\n- `@stopwatch` measures execution time of a function (upon being called) and prints the time taken in seconds to the console.\n- `@catch` catches exceptions from a function.\n- `@enforce_types` checks types of function arguments and return value (raises TypeError if types don't match).\n\n### Functions:\n- `parse_string` splits a string by separators and applies the provided converter to each substring.\n- `parse_file_content` same as `parse_string`, but parses file content instead of a string.\n- `b64encode` encodes a string to a base64 string a specified number of times.\n- `b64decode` decodes a base64 string a specified number of times.\n- `tm_snapshot_to_string` builds a readable string from the given `tracemalloc` snapshot.\n\n### Classes:\n- `CaptureMalloc` captures memory allocations within a block of code (context manager).\n- `Cell` represents a location in a 2-dimensional grid, with attributes for `row` and `column`.\n- `Grid` represents a 2-dimensional grid, provides various operations to manipulate and query the grid.\n\n## Installation\n```bash\npip install utils-anviks\n```\n\n## Usage\n\n```python\nimport time\nimport tracemalloc\nfrom utils_anviks import stopwatch, catch, enforce_types, parse_string, parse_file_content, b64encode, b64decode, \\\n    tm_snapshot_to_string, CaptureMalloc, Grid, Cell\n\n\n@stopwatch\ndef foo():\n    time.sleep(1.23)\n\n\n@catch(TypeError, ZeroDivisionError)\ndef bar(n: int):\n    return 1 / n\n\n\n@enforce_types\ndef baz(n: int) -\u003e int:\n    pass\n\n\nfoo()  # Time taken by the function to execute is printed to the console\nprint(bar(0))  # Catches ZeroDivisionError and returns (1, [error object])\nbaz('string')  # Raises TypeError\n\nprint(parse_string('111,222,333\\n64,59,13', ('\\n', ','), int))  # [[111, 222, 333], [64, 59, 13]]\nprint(parse_file_content('file.txt', ('\\n', ','), int))  # Same as above, but reads from a file\n\nprint(b64encode('string', 3))  # 'WXpOU2VXRlhOVzQ9'\nprint(b64decode('WXpOU2VXRlhOVzQ9', 3))  # 'string'\n\ntracemalloc.start()\narr1 = [i for i in range(100_000)]  # Arbitrarily chosen memory allocation\nsnapshot = tracemalloc.take_snapshot()\ntracemalloc.stop()\nprint(tm_snapshot_to_string(snapshot))\n\nwith CaptureMalloc() as cm:\n    arr2 = [i for i in range(100_000)]  # Arbitrarily chosen memory allocation\nprint(cm.snapshot_string)\n# Top 3 lines\n# #1: AOC\\dsjdfskld.py:41: 3.8 MiB\n#     arr2 = [i for i in range(100_000)]  # Arbitrarily chosen memory allocation\n# Total allocated size: 3.8 MiB\n\n\nprint(Cell(5, 5).neighbours('cardinal'))\n# (Cell(row=4, column=5), Cell(row=5, column=6), Cell(row=6, column=5), Cell(row=5, column=4))\nprint(Cell(3, 2).up.up.up.left.left)\n# Cell(row=0, column=0)\n\nprint(grid := grid.map(lambda cell, value: 'X' if cell.is_neighbour(Cell(2, 3), 'all') else ' ').join_to_str())\n#      \n#   XXX\n#   X X\n#   XXX\n#      \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanviks%2Futils-anviks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanviks%2Futils-anviks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanviks%2Futils-anviks/lists"}