implant

asynchronous adhoc remote procedure calls in Python

https://github.com/diefans/implant

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.4%) to scientific vocabulary

Keywords

asyncio bot code implant python3 rpc
Last synced: 6 months ago · JSON representation

Repository

asynchronous adhoc remote procedure calls in Python

Basic Info
  • Host: GitHub
  • Owner: diefans
  • License: apache-2.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 483 KB
Statistics
  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
asyncio bot code implant python3 rpc
Created over 9 years ago · Last pushed over 7 years ago
Metadata Files
Readme License

README.rst

.. container:: bagdes

    .. image:: https://travis-ci.org/diefans/implant.svg?branch=master
       :target: https://travis-ci.org/diefans/implant
       :align: right

    .. image:: https://img.shields.io/pypi/pyversions/implant.svg
       :target: https://pypi.org/project/implant/
       :alt: PyPI - Python Version

    .. image:: https://img.shields.io/pypi/v/implant.svg
       :target: https://pypi.org/project/implant/
       :alt: PyPI

    .. image:: https://img.shields.io/readthedocs/implant.svg
       :target: http://docs.implant.codes
       :alt: Read the Docs

    .. image:: https://codecov.io/gh/diefans/implant/branch/master/graph/badge.svg
       :target: https://codecov.io/gh/diefans/implant

----

.. image:: implant.png
   :alt: implant
   :align: left


implant
**********

A proof-of-concept for asynchronous adhoc remote procedure calls in Python.

This is work in progress and serves basically as an exercise.


.. inclusion-marker-do-not-remove


Features
========

- Python >= 3.5 asyncio

- adhoc transferable remote procedures

- remote part of a `implant.core.Command` may reside in a separate module

- a `implant.core.Command` specific `implant.core.Channel`
  enables arbitrary protocols between local and remote side

- events

- quite small core

- tests


Limitations
===========

- Python >= 3.5

- only pure Python modules are supported for remote import, if no venv is used

- `implant.core.Command` s must reside in a module other then `__main__`

- at the moment sudo must not ask for password



Example
=======


General application
-------------------

.. code:: python

    import asyncio
    import pathlib

    from implant import core, connect, commands


    async def remote_tasks():
        # create a connector for a python process
        connector = connect.Lxd(
            container='zesty',
            hostname='localhost'
        )
        connector_args = {
            'python_bin': pathlib.Path('/usr/bin/python3')
        }
        # connect to a remote python process
        remote = await connector.launch(**connector_args)

        # start remote communication tasks
        com_remote = asyncio.ensure_future(remote.communicate())
        try:
            # execute command
            cmd = commands.SystemLoad()
            result = await remote.execute(cmd)

            print("Remote system load:", result)

        finally:
            # stop communication tasks
            com_remote.cancel()
            await com_remote


    if __name__ == '__main__':
        loop = asyncio.get_event_loop()
        loop.run_until_complete(remote_tasks())
        loop.close()


An example Echo Command
-----------------------

.. code:: python

    import logging
    import os

    from implant import core


    log = logging.getLogger(__name__)


    class Echo(core.Command):

        """Demonstrate the basic command API."""

        async def local(self, context):
            """The local side of the RPC.

               :param context: :py:obj:`implant.core.DispatchLocalContext`
            """
            # custom protocol
            # first: send
            await context.channel.send_iteration("send to remote")

            # second: receive
            from_remote = []
            async for x in context.channel:
                from_remote.append(x)
            log.debug("************ receiving from remote: %s", from_remote)

            # third: wait for remote to finish and return result
            remote_result = await context.remote_future

            result = {
                'from_remote': ''.join(from_remote),
            }
            result.update(remote_result)
            return result

        async def remote(self, context):
            """The remote side of the RPC.

               :param context: :py:obj:`implant.core.DispatchRemoteContext`
            """
            # first: receive
            from_local = []
            async for x in context.channel:
                from_local.append(x)
            log.debug("************ receiving from local: %s", from_local)

            # second: send
            await context.channel.send_iteration("send to local")

            # third: return result
            return {
                'from_local': ''.join(from_local),
                'remote_self': self,
                'pid': os.getpid()
            }


Internals
=========

::

    master <-----------------------------------------> remote
                                |
                           stdin/stdout
                                |
                              chunks
                                |
                             channels
                                |
        --> send ---> |                   |  --> queue -->
                      | module:class/fqin |
        <-- queue <-- |                   |  <--- send <--

Owner

  • Name: Oliver Berger
  • Login: diefans
  • Kind: user
  • Location: Berlin
  • Company: freelancer

GitHub Events

Total
Last Year

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 239
  • Total Committers: 1
  • Avg Commits per committer: 239.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Oliver Berger o****r@d****e 239
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 33 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 3
  • Total maintainers: 1
pypi.org: implant

Remote execution via stdin/stdout messaging.

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 33 Last month
Rankings
Dependent packages count: 10.0%
Dependent repos count: 21.7%
Average: 26.2%
Stargazers count: 27.8%
Forks count: 29.8%
Downloads: 41.9%
Maintainers (1)
Last synced: 6 months ago