Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Import From GitHub in Python

DZone's Guide to

How to Import From GitHub in Python

Learn how to grab code directly from GitHub while in Python through an experimental package that utilizes new import hooks in PEP 302.

· Agile Zone
Free Resource

See how three solutions work together to help your teams have the tools they need to deliver quality software quickly. Brought to you in partnership with CA Technologies

The other day, I came across this interesting experimental package for Python called import_from_github_com. The package uses the new import hooks provided in PEP 302 to basically allow you to import a package from github. What the package actually appears to do is install the package and add it to locals. You need Python 3.2 or greater, git and pip to use this package.

Once it’s installed, you can do the following:

>>> from github_com.zzzeek import sqlalchemy
Collecting git+https://github.com/zzzeek/sqlalchemy
  Cloning https://github.com/zzzeek/sqlalchemy to /tmp/pip-acfv7t06-build
Installing collected packages: SQLAlchemy
  Running setup.py install for SQLAlchemy ... done
Successfully installed SQLAlchemy-1.1.0b1.dev0
>>> locals()
{'__builtins__': <module 'builtins' (built-in)>, '__spec__': None,
 '__package__': None, '__doc__': None, '__name__': '__main__', 
'sqlalchemy': <module 'sqlalchemy' from '/usr/local/lib/python3.5/site-packages/sqlalchemy/__init__.py'>,
 '__loader__': <class '_frozen_importlib.BuiltinImporter'>}

One important note that isn’t mentioned on the package’s github page is that you need to run Python as an administrator or it won’t be able to install its packages. At least, this was true for me on Xubuntu. Anyway I thought this was a neat little package and demonstrates some of neat little import hooks that you can add to Python 3.

Discover how TDM Is Essential To Achieving Quality At Speed For Agile, DevOps, And Continuous Delivery. Brought to you in partnership with CA Technologies

Topics:
python ,github ,user guide

Published at DZone with permission of Mike Driscoll, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}