{"id":29027048,"url":"https://github.com/devl/pyby","last_synced_at":"2025-06-26T06:02:42.958Z","repository":{"id":40328713,"uuid":"467458009","full_name":"DevL/Pyby","owner":"DevL","description":"A library implementing certain Ruby-like behaviours in Python.","archived":false,"fork":false,"pushed_at":"2022-05-31T09:13:56.000Z","size":116,"stargazers_count":2,"open_issues_count":12,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-11T08:09:22.719Z","etag":null,"topics":["enumerable","python3","ruby"],"latest_commit_sha":null,"homepage":"https://devl.github.io/Pyby","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/DevL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-08T10:07:30.000Z","updated_at":"2024-01-28T00:15:17.000Z","dependencies_parsed_at":"2022-08-09T17:21:05.654Z","dependency_job_id":null,"html_url":"https://github.com/DevL/Pyby","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/DevL/Pyby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2FPyby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2FPyby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2FPyby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2FPyby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevL","download_url":"https://codeload.github.com/DevL/Pyby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2FPyby/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262010857,"owners_count":23244411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["enumerable","python3","ruby"],"created_at":"2025-06-26T06:02:41.753Z","updated_at":"2025-06-26T06:02:42.943Z","avatar_url":"https://github.com/DevL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pyby\n\n**NB:** This repository has been moved to [https://codeberg.org/DevL/pypy](https://codeberg.org/DevL/pyby).\n\n![PyPI](https://img.shields.io/pypi/v/pyby)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyby)\n![PyPI - Status](https://img.shields.io/pypi/status/pyby)\n![PyPI - License](https://img.shields.io/pypi/l/pyby)\n![based on Ruby](https://img.shields.io/badge/based%20on%20Ruby-3.1.2-red)\n[![Python package](https://github.com/DevL/pyby/actions/workflows/python-package.yml/badge.svg)](https://github.com/DevL/pyby/actions/workflows/python-package.yml)\n\n\nA library implementing certain Ruby-like behaviours in Python.\n\n**NB:** This is heavily under development and subject to change. Expect breaking changes until the 1.0.0 release.\n\n## Installation\n\nInstall the `pyby` package from [PyPI](https://pypi.org/project/pyby).\n\n```sh\npip install pyby\n```\n\n## Current Functionality\n\nThe links in the list of available modules, classes, methods, and functions below link to the corresponding Ruby documentation.\n\nCurrently, Ruby version 3.1.2 is used as a basis for the mimiced functionality.\n\n### [`RObject`](https://ruby-doc.org/core-3.1.2/Object.html) (object.py)\n\nA base class to enrich Python objects with additional functionality.\n\n#### [`respond_to`](https://ruby-doc.org/core-3.1.2/Object.html#method-i-respond_to-3F)\n\nDetermines whether an object has a certain callable property or not.  \nAlso available as a standalone function, rather than a method.\n\n#### [`send`](https://ruby-doc.org/core-3.1.2/Object.html#method-i-send)\n\nCalls the property identified by name, passing it any arguments specified.\nIf the property is not callable and no arguments are specified, the property is instead returned.\n\n---\n\n### [`Enumerable`](https://ruby-doc.org/core-3.1.2/Enumerable.html) (enumerable.py)\n\nA base class meant to be subclassed by an iterable (henceforth referred to as an enumerable).  \nThe enumerable must implement `__each__` in order to unlock the rest of the functionality.\n\nTo return something else than an `EnumerableList`, the enumerable can override `__into__`. For example, `EnumerableDict` returns another `EnumerableDict` when its `compact` method is called.\n\nIn addition, the enumerable may override `__to_tuple__` in order to support predicate and mapping functions with a higher arity than one. A prime example would be `EnumerableDict` in combination with `select` where the predicate function should expect the key-value pair split into two arguments rather than a single tuple. In this case, `__to_tuple__` should return the key-value pair as a two-element tuple. \n\n#### `__each__` (internal)\n\nReturns an iterator to be used internally.  \nMust be implemented by the subclass.\n\n#### `__into__` (internal)\n\nReturns a constructor that accepts an iterable for the given method name.  \nBy default imports and returns `EnumerableList`.  \nMay be implemented by the subclass.\n\n#### `__to_tuple__` (internal)\n\nTransforms a single element of an enumerable to a tuple.  \nUsed internally to uniformly handle predicate and mapping functions with a higher arity than one.  \nBy default returns the item wrapped in a single-element tuple.  \nMay be implemented by the subclass.\n\n#### `configure` (internal)\n\nA decorator enabling the return type of a method, as well as the number of arguments predicate and mapping functions are to be called with, to be configured by the collection class inheriting from Enumerable.  \nIf `enumerator_without_func` is set, the decorator skips calling the decorated method if no arguments have been passed and instead returns an Enumerator based on the enumerable.\n\nRelys on the enumerable's implementation of `__into__` and `__to_tuple__`.\n\n#### [`collect`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-collect), [`map`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-map)\n\nReturns the result of mapping a function over the elements.  \nThe mapping function takes a single argument for sequences and two arguments for mappings.\n\n#### [`collect_concat`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-collect_concat), [`flat_map`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-flat_map)\n\nReturns the flattened result of mapping a function over the elements.\nThe mapping function takes a single argument for sequences and two arguments for mappings.\n\n#### [`compact`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-compact)\n\nReturns an enumerable of the elements with None values removed.\n\n#### [`count`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-count)\n\nReturns the number of elements in the enumerable.\n\nOptionally accepts an argument.  \nGiven a non-callable argument, counts the number of equivalent elements.  \nGiven a callable predicate, counts the elements for which the predicate is truthy.\n\n#### [`detect`](https://ruby-doc.org/core-3.1.2/enumerable.html#method-i-detect), [`find`](https://ruby-doc.org/core-3.1.2/enumerable.html#method-i-find)\n\nReturns the first element for which the predicate function is truthy. If no matching element is found, returns `None`, unless a default callback has been provided, in which turn that callback function will be invoked and its result returned. The predicate function takes a single argument for sequences and two arguments for mappings.\n\nIf called with a single argument, treats it as the predicate function.  \nIf called with two arguments, the first is treated as the default callback function and the second argument acts as the predicate function.\n\nWithout a predicate function, returns an enumerator by calling to_enum.\n\n#### [`each`](https://ruby-doc.org/core-3.1.2/Enumerable.html#module-Enumerable-label-Enumerable+in+Ruby+Core+Classes)\n\nGiven a function, calls the function once for each item in the enumerable.  \nFor sequences this will typically be the same as iterating over the elements,\nwhereas for mappings this will be same as iterating over the items.\n\nWithout a function, returns an enumerator by calling `to_enum`.\n\n#### [`filter`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-filter), [`find_all`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-find_all), [`select`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-select)\n\nReturns the elements for which the predicate function is truthy.  \nThe predicate function takes a single argument for sequences and two arguments for mappings.\n\nWithout a predicate function, returns an enumerator by calling to_enum.\n\n#### [`first`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-first)\n\nReturns the first element or a given number of elements.  \nWith no argument, returns the first element, or `None` if there is none.  \nWith a number of elements requested, returns as many elements as possible.\n\n#### [`include`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-include-3F), [`member`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-member-3F) \n\nReturns whether the enumerable includes the element.  \nFor mappings this is determined as a key with the same name existing.\n\n#### [`inject`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-inject), [`reduce`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-reduce)\n\nPerforms a reduction operation much like `functools.reduce`.  \nIf called with a single argument, treats it as the reduction function.  \nIf called with two arguments, the first is treated as the initial value for the reduction and the second argument acts as the reduction function.\n\nAlso available as the alias `reduce`.\n\n#### [`reject`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-reject)\n\nReturns the elements for which the predicate function is falsy.  \n\nWithout a predicate function, returns an enumerator by calling to_enum.\n\n#### [`take`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-take)\n\nReturns the number of elements requested or as many elements as possible.\n\n#### [`to_enum`](https://ruby-doc.org/core-3.1.2/Object.html#method-i-to_enum)\n\nReturns an `Enumerator` for the enumerable.  \nRequires an iterable subclass.\n\n#### [`uniq`](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-uniq)\n\nWithout a function, returns only unique elements.\nWith a function, returns only elements for which the function returns a unique value.\n\n---\n\n### [`EnumerableDict`](https://ruby-doc.org/core-3.1.2/Hash.html) (enumerable_dict.py)\n\nA subclass of `Enumerable` that mimics some of Ruby's `Hash` while still behaving like a Python `dict`.\n\n---\n\n### [`EnumerableList`](https://ruby-doc.org/core-3.1.2/Array.html) (enumerable_list.py)\n\nA subclass of `Enumerable` that mimics some of Ruby's `Array` while still behaving like a Python `list`.\n\n---\n\n### [`Enumerator`](https://ruby-doc.org/core-3.1.2/Enumerator.html) (enumerator.py)\n\nA class which allows both internal and external iteration.  \nAn enumerator is in turn an enumerable.\n\n#### [`next`](https://ruby-doc.org/core-3.1.2/Enumerator.html#method-i-next)\n\nReturns the next object in the enumeration sequence.  \nIf going beyond the enumeration, `StopIteration` is raised.\n\n#### [`peek`](https://ruby-doc.org/core-3.1.2/Enumerator.html#method-i-peek)\n\nReturns the current object in the enumeration sequence without advancing the enumeration.  \nIf going beyond the enumeration, `StopIteration` is raised.\n\n#### [`rewind`](https://ruby-doc.org/core-3.1.2/Enumerator.html#method-i-rewind)\n\nRewinds the enumeration sequence to the beginning.\n\n_Note that this may not be possible to do for underlying iterables that can be exhausted._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevl%2Fpyby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevl%2Fpyby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevl%2Fpyby/lists"}