{"id":20074026,"url":"https://github.com/ezforever/pytrickz","last_synced_at":"2026-06-09T19:31:08.444Z","repository":{"id":114511374,"uuid":"376494130","full_name":"EZForever/pytrickz","owner":"EZForever","description":"Everyone needs a \"pytricks\" repo for their nasty handy Python hacks.","archived":false,"fork":false,"pushed_at":"2021-06-24T16:43:22.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T12:28:05.242Z","etag":null,"topics":["cpython","functional","hack","pipeline","python","syntax-sugar"],"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/EZForever.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2021-06-13T09:14:39.000Z","updated_at":"2022-05-12T11:30:00.000Z","dependencies_parsed_at":"2023-05-17T14:15:15.593Z","dependency_job_id":null,"html_url":"https://github.com/EZForever/pytrickz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EZForever/pytrickz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EZForever%2Fpytrickz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EZForever%2Fpytrickz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EZForever%2Fpytrickz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EZForever%2Fpytrickz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EZForever","download_url":"https://codeload.github.com/EZForever/pytrickz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EZForever%2Fpytrickz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34123171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cpython","functional","hack","pipeline","python","syntax-sugar"],"created_at":"2024-11-13T14:49:07.030Z","updated_at":"2026-06-09T19:31:08.427Z","avatar_url":"https://github.com/EZForever.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytrickz\r\n\r\n*A library aimed for providing handy hacks for your daily coding task.*\r\n\r\n## What is this\r\n\r\nSome syntactic sugar taken from various languages' designs added to Python3 for some coding ease. They are anti-Pythonic and even \"Java (or C#) flavored\", but they are intuitive (at least to me) and gets the job done.\r\n\r\n```python\r\n\u003e\u003e\u003e from pytrickz import *\r\n\u003e\u003e\u003e from pytrickz.extensions import *\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Chaining iterable operations\r\n\u003e\u003e\u003e stream.of(1, 2, 3).map(lambda x: x ** 2).to(list)\r\n[1, 4, 9]\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Regexp-enabled string operations\r\n\u003e\u003e\u003e 'Albert Einstein'.rematch(r'(\\w+) (\\w+)').group(2)\r\n'Einstein'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Looped XOR. Everyone's favorite bit operation.\r\n\u003e\u003e\u003e b'abcdef' ^ 0x50\r\nb'123456'\r\n\u003e\u003e\u003e \r\n```\r\n\r\n## Installation \u0026 usage\r\n\r\nInstall directly from GitHub:\r\n\r\n```\r\n$ pip3 install -U git+https://github.com/EZForever/pytrickz\r\n```\r\n\r\nIf you need things in the `pybrickz.extensions` package, [`forbiddenfruit`][forbiddenfruit] need to be installed. Note that `forbiddenfruit` only supports CPython.\r\n\r\nStart using right away with `from pytrickz import *`. All features are documented via docstrings so use `help()` if you need guidance.\r\n\r\n## Feature highlights\r\n\r\nFor full feature list, try `help(pytrickz)`. That might help.\r\n\r\n### `stream`\r\n\r\nIdea ~~stolen~~ borrowed from [`Stream\u003cT\u003e` class in Java 8+][stream-api], allows chaining operations on an iterable and have them lazy-evalulated.\r\n\r\n```python\r\n\u003e\u003e\u003e from pytrickz import stream\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Currently `stream` support ~30 common operations. `help(stream)` for more.\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Crunching numbers\r\n\u003e\u003e\u003e # Newlines are completely optional, added only for readability\r\n\u003e\u003e\u003e stream.of(1, 1, 4, 5, 1, 4) \\\r\n...     .unique() \\\r\n...     .map(lambda x: x ** 2) \\\r\n...     .filter(lambda x: x % 2) \\\r\n...     .sum()\r\n... \r\n26\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Hexadecimal countdown because why not\r\n\u003e\u003e\u003e stream.range(15, 0) \\\r\n...     .map('0123456789abcdef'.__getitem__) \\\r\n...     .to(list)\r\n... \r\n['f', 'e', 'd', 'c', 'b', 'a', '9', '8', '7', '6', '5', '4', '3', '2', '1']\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Transposing a 4x4 \"matrix\"\r\n\u003e\u003e\u003e my_mat = '048c159d26ae37bf'\r\n\u003e\u003e\u003e stream(my_mat) \\\r\n...     .group(4) \\\r\n...     .zip() \\\r\n...     .flatten() \\\r\n...     .join()\r\n... \r\n'0123456789abcdef'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Even basic I/O with CSV files\r\n\u003e\u003e\u003e stream.fromcsv('example.csv', *(float, None, None, float, float)) \\\r\n...     .starmap(lambda mean, mn, mx: (mean, mx - mn)) \\\r\n...     .enumerate() \\\r\n...     .starmap(lambda idx, data: (idx + 1, *data)) \\\r\n...     .tocsv('out.csv', *('gen', 'frames_mean', 'frames_range'))\r\n... \r\n\u003e\u003e\u003e \r\n```\r\n\r\n### `@extension`\r\n\r\nA concept [from C#][extension-methods]. Prepend your method definition with `@extension` and your method appears in every instance of the target class.\r\n\r\n```python\r\n\u003e\u003e\u003e from pytrickz import extension\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # This example needs `forbiddenfruit` to work, since it extends built-in types. `help(extension)` for more info.\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e @extension\r\n... def my_reversed(self: str) -\u003e str: # Type annotation on `self` is necessary, similar to writing `this String` in C#\r\n...     return self[ : : -1]\r\n... \r\n\u003e\u003e\u003e '123456'.my_reversed()\r\n'654321'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Properties work too\r\n\u003e\u003e\u003e @extension\r\n... @property\r\n... def length(self: str) -\u003e int:\r\n...     return len(self)\r\n... \r\n\u003e\u003e\u003e '123456'.length\r\n6\r\n```\r\n\r\n### Handy extensions for built-in types\r\n\r\nUsing `@extension` we can extend built-in types to provide even more handy stuff.\r\n\r\n```python\r\n\u003e\u003e\u003e from pytrickz.extension import *\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # The above statement enables all extensions. `help(pytrickz.extension)` for all available modules.\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Regexp-enabled string operations\r\n\u003e\u003e\u003e 'Albert Einstein'.rematch(r'(\\w+) (\\w+)').group(2)\r\n'Einstein'\r\n\u003e\u003e\u003e '1.jpg 2.png'.refindall(r'\\.\\w{2}g') # Use .refind() if only need the first match\r\n[\u003cre.Match object; span=(1, 5), match='.jpg'\u003e, \u003cre.Match object; span=(7, 11), match='.png'\u003e]\r\n\u003e\u003e\u003e '1.jpg 2.png'.rereplace(r'\\.\\w{2}g', '.gif')\r\n'1.gif 2.gif'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Hex \u0026 Base64 encoding\r\n\u003e\u003e\u003e '313233343536'.unhex() # Also .b64decode()\r\nb'123456'\r\n\u003e\u003e\u003e b'123456'.b64encode() # Also .hex()\r\n'MTIzNDU2'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Checksum calculation\r\n\u003e\u003e\u003e b'123456'.cksum() # CRC-32; name from GNU coreutils\r\n'0972d361'\r\n\u003e\u003e\u003e b'123456'.md5sum() # Also .sha1sum() and .sha256sum()\r\n'e10adc3949ba59abbe56e057f20f883e'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Looped XOR on bytes\r\n\u003e\u003e\u003e b'ABCDEFGH' ^ b'123456'\r\nb'ppppppvz'\r\n\u003e\u003e\u003e b'abcdef' ^ 0x50\r\nb'123456'\r\n\u003e\u003e\u003e \r\n\u003e\u003e\u003e # Comparsion \u0026 arithmetic operators for ctypes integers\r\n\u003e\u003e\u003e # NOTE: Not stable and not feature complete\r\n\u003e\u003e\u003e from ctypes import *\r\n\u003e\u003e\u003e a, b = c_int(1), c_int(2)\r\n\u003e\u003e\u003e a \u003c b\r\nTrue\r\n\u003e\u003e\u003e a + 1 == b\r\nTrue\r\n\u003e\u003e\u003e \r\n```\r\n\r\n[forbiddenfruit]: https://pypi.org/project/forbiddenfruit/\r\n[stream-api]: https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html\r\n[extension-methods]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezforever%2Fpytrickz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezforever%2Fpytrickz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezforever%2Fpytrickz/lists"}