Skip to main content

Copilot Importer

Why write code when you can import it directly from GitHub Copilot?

What is Copilot Importer?

The copilot python module will dynamically generate any function imported by leveraging the GitHub Copilot service.

How do I use Copilot Importer?

You can install copilot-importer via pip (e.g. pip install copilot-importer).

Additionally and importantly, you need a GitHub Copilot API token. See How do I get an authentication token.

Once you have your token, set it to the environment variable GITHUB_COPILOT_TOKEN.

export GITHUB_COPILOT_TOKEN=xxxxxxxxxxxxxxxxxxxx

Finally, before the dynamic importing feature is enabled, you must run the copilot.install method.

# Enable copilot importer
from copilot import install
install()

After all of the above has been taken care of, you should be able to import anything you want directly from GitHub Copilot:

>>> from copilot import install
>>> install()

>>> from copilot import base64_encode
>>> base64_encode(b"test")
b'dGVzdA=='

>>> from copilot import base64_decode
>>> base64_decode(base64_encode(b"test"))
b'test'

>>> from copilot import quicksort
>>> quicksort([5,2,3,4])
[2, 3, 4, 5]

You can also output the code of imported functions like so:

>>> from copilot import say_hello
>>> print(say_hello._code)
def say_hello():
    print("Hello, World!")

How do I get an authentication token?

To obtain an authentication token to the Copilot API, you will need a GitHub account with access to Copilot.

copilot-importer has an authentication CLI built-in, which you can use to fetch your copilot authentication token. To star the authentication process after installing copilot-importer, simply run

copilot-auth

OR

python -m copilot

OR

python -c "from copilot.authflow import run; run()"

Once you have started the authentication flow, you will be prompted to enter a device authorization code to https://github.com/login/device.

After entering the correct code, you will be asked to authorize GitHub for VSCode to access your account. This is expected, as the Copilot API is only accessible to the VSCode plugin.

Once approved, you should see a Copilot access token printed to the terminal.

Example:

$ copilot-auth
Initializing a login session...
YOUR DEVICE AUTHORIZATION CODE IS: XXXX-XXXX
Input the code to https://github.com/login/device in order to authenticate.

Polling for login session status until 2021-07-17T17:26:01.618386
Polling for login session status: authorization_pending
Polling for login session status: authorization_pending
Successfully obtained copilot token!


YOUR TOKEN: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
EXPIRES AT: 2021-07-17T21:21:39

You can add the token to your environment e.g. with
export GITHUB_COPILOT_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Credits

  • Inspiration taken from stack-overflow-import
  • GitHub for providing GitHub Copilot.
  • molenzwiebel for working out the Copilot API and helping with the code.
  • akx for giving a quick review of the code.

Metadata

Release files for copilot-import 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for copilot-import 1.0.0
File Size Uploaded
copilot-import-1.0.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for copilot-import 1.0.0
File Interpreter ABI Platform
copilot_import-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / copilot-import-1.0.0.tar.gz

Download URL copilot-import-1.0.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f0709fe886a014e46d0bf3d19838960f1e74236922d566df412ddee6370043b4
BLAKE2b-256 checksum
How to use checksums
02fcc1f299335f0ba0391c5046ef49b59686a6fe85c07f319d0681c1f179f49e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.6 Windows/10

Release files / copilot_import-1.0.0-py3-none-any.whl

Download URL copilot_import-1.0.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50f2d35f6ccf59079f9de9825493b564e22ab7e75db224c52e6498578576a6f5
BLAKE2b-256 checksum
How to use checksums
131461beb21e4f109861e97c8bee4d25f70d5a80471a34015cfa9d55f4572388
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.6 Windows/10

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page