{"id":16722219,"url":"https://github.com/tkluck/pyperler","last_synced_at":"2025-04-10T10:07:41.188Z","repository":{"id":12328852,"uuid":"14967107","full_name":"tkluck/pyperler","owner":"tkluck","description":"Use perl scripts and libraries from Python","archived":false,"fork":false,"pushed_at":"2020-02-14T10:20:22.000Z","size":150,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T08:55:39.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkluck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-05T22:05:32.000Z","updated_at":"2024-04-26T19:32:13.000Z","dependencies_parsed_at":"2022-09-10T16:33:09.501Z","dependency_job_id":null,"html_url":"https://github.com/tkluck/pyperler","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkluck%2Fpyperler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkluck%2Fpyperler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkluck%2Fpyperler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkluck%2Fpyperler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkluck","download_url":"https://codeload.github.com/tkluck/pyperler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198882,"owners_count":21063628,"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":[],"created_at":"2024-10-12T22:34:01.258Z","updated_at":"2025-04-10T10:07:41.159Z","avatar_url":"https://github.com/tkluck.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"PyPerler\n========\n[![][travis-img]][travis-url]\n\n[travis-img]: https://travis-ci.org/tkluck/pyperler.svg?branch=master\n[travis-url]: https://travis-ci.org/tkluck/pyperler\n\nQuick introduction\n------------------\nPyPerler gives you the power of CPAN, and your perl packages, in Python.  Using\nPerl stuff is as easy as:\n\n    \u003e\u003e\u003e import pyperler; i = pyperler.Interpreter()\n    \u003e\u003e\u003e # use a CPAN module\n    \u003e\u003e\u003e Table = i.use('Text::Table')\n    \u003e\u003e\u003e t = Table(\"Planet\", \"Radius\\nkm\", \"Density\\ng/cm^3\")\n    \u003e\u003e\u003e _ = t.load(\n    ...    [ \"Mercury\", 2360, 3.7 ],\n    ...    [ \"Venus\", 6110, 5.1 ],\n    ...    [ \"Earth\", 6378, 5.52 ],\n    ...    [ \"Jupiter\", 71030, 1.3 ],\n    ... )\n    \u003e\u003e\u003e print( t.table() )\n    Planet  Radius Density\n            km     g/cm^3 \n    Mercury  2360  3.7    \n    Venus    6110  5.1    \n    Earth    6378  5.52   \n    Jupiter 71030  1.3    \n    \u003cBLANKLINE\u003e\n\nIf you install the `Class::Inspector` CPAN package, then PyPerler will even get\nyou introspection for use in IPython.\n\nQuick install\n-------------\n\nYou'll need cython, perl and the perl headers. On Ubuntu, these are just\n\n    $ sudo apt-get install cython perl-base perl\n\nThen compilation and installation is \n\n    $ python setup.py build \u0026\u0026 sudo python setup.py install\n\nThis works both for python2 and python3.\n\nOverview\n------------\nPyPerler allows you to seemlessly interact with Perl code from Python. Python\ndicts and Perl hashes map into eachother transparently, and so do lists and\narrays.\n\nThe obvious complications for bridging the differences between Python and Perl are\n\n 1. Weak typing; there's no difference between 1 and \"1\" in Perl\n 2. Void context vs. scalar context vs. list context\n\nFor choosing a strategy to deal with this, we follow the Philosophy of Python:\n\n    Explicit is better than implicit.\n    (...)\n    In the face of ambiguity, refuse the temptation to guess.\n\nOn the other hand, we are not shying away from Perl's There Is More Than One Way\nTo Do It. For example, these both give the same results:\n\n    \u003e\u003e\u003e [int(x) for x in i[\"1 .. 10\"]]\n    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n    \u003e\u003e\u003e i[\"1 .. 10\"].ints()\n    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n\nWeak typing\n-----------\nWhenever we return a scalar value from Perl, this remains boxed as an object of\ntype pyperler.ScalarValue.  This can either be explicitly cast to bytes, str,\nint, or float, or that can happen implicitly through type inference in binary\noperations. We 'refuse the tempation to guess' when applying a binary operator\nto TWO pyperler.ScalarValue instances: this raises a TypeError.\n\nIn case the scalar value is a hashref resp. an arrayref, it supports all the\noperations that Python's built-in dict object resp. list object support.\n\nIn case the scalar value is a blessed reference, it additionally supports\nmethods calls. When there's a naming clash between the Python built-in method\nand the blessed reference's methods, the Python ones take precedence. The \"hidden\"\nmethods are still available through an indexable attribute 'F', like so:\n\n    \u003e\u003e\u003e arrayref = i('package a; sub append { 42 }; bless [], \"a\"')\n    \u003e\u003e\u003e arrayref.F['append'](23)\n    42\n\nVoid context vs. scalar context vs. list context\n------------------------------------------------\nAny pyperler object that represents a Perl callable has methods `void_context`,\n`list_context`, and `scalar_context`. In addition, `__call__` (ie the function\ncall operator) is a shorthand for `scalar_context`.\n\nSimilarly, the Interpreter object has methods `void_context`, `list_context`,\nand `scalar_context`. They take a single string as an argument, which is evaluated\nas Perl code. `__call__` is a shorthand for `scalar_context`, and also `__getitem__`\nis a shorthand for `list_context`. (This last  thing wouldn't be useful for\ncallables, because the case of zero arguments is a syntax error in Python.)\n\n`void_context` returns None\n`scalar_context` returns a pyperler.ScalarValue\n`list_context` returns a pyperler.ListValue. This is just a python tuple of\npyperler.ScalarValue objects, with a few convenience methods for casting all of\nthem.\n\nLicense\n-------\nPyPerler is Copyright (C) 2013-2015, Timo Kluck. It is distributed under the\nGeneral Public License, version 3 or later.\n\nThe file PythonObject.pm contains code from from PyPerl, which is Copyright\n2000-2001 ActiveState. This code can be distributed under the same terms as\nPerl, which includes distribution under the GPL version 1 or later.\n\nFor your convenience, the General Public License version 3 is included as the\nfile COPYING.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkluck%2Fpyperler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkluck%2Fpyperler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkluck%2Fpyperler/lists"}