Skip to main content

Allows to import zip-compressed Python package by URL (http, hdfs).

Project description

Test Status

Allows to import zip-compressed Python package by URL.

Download remote zip-compressed Python package, unzip and add to Python path.

All temp files will be removed on exit unless Python process was terminated.

Note: import should be called separatelly after calling importable. All we do here - just adding package to local python path.

Supported URL types

importable supports a limited set of URL types:

  1. Http url to zip file: http(s)://<url>/<filename>.zip

    The module, which you are going to import, should be located on the first level of <filename>.zip

    See section Example.

  2. Http url to zip file on GitHub: http(s)://github.com/<path>/<filename>.zip

    Similar to the previous type except that module is located inside an additional directory (in <filename>.zip).

  3. Hdfs url to zip file: webhdfs://<host>:<port>/<path>/<filename>.zip

    Similar to #1 except that file will be downloaded from HDFS.

    <host> - hostname or IP address of Hdfs namenode <port> - WebHdfs port of namenode

Install

Using pip:

$ pip install importable

Usage

Make remote package importable, then import it and use:

from importable import importable


# add contents of "<filename>.zip" to python path
importable('http://<url>/<filename>.zip')

# now you can import your module
import <module_name>

Example

Assuming that you have local nginx serving /var/www/html/ on port 80.

$ mkdir mymodule
$ echo "my_var = 'I want to import this one!'" > mymodule/__init__.py
$ zip -r mymodule.zip mymodule
$ mv mymodule.zip /var/www/html

Then execute the python code:

>>> import mymodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'mymodule'
>>> from importable import importable
>>> importable('http://localhost/mymodule.zip')
>>> import mymodule
>>> print(mymodule.my_var)
I want to import this one!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

importable-0.2.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

importable-0.2.2-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file importable-0.2.2.tar.gz.

File metadata

  • Download URL: importable-0.2.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for importable-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ba126c273f78dfc9bcaef59902b0a232ad8cd129b7604e2e226ed968d22b6b6d
MD5 ce6081e05cd0120562bdd81100f1be56
BLAKE2b-256 ef0fa64c5a0537032ada7fc9518add94237929a1461814ca1c5dc4450e3f2e49

See more details on using hashes here.

File details

Details for the file importable-0.2.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for importable-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d2c3aeac8ca7d06fea82b6f69f7e68d44f8e568ab74cd073a18408928854a9e6
MD5 95f39e370f87ba512bc184fbd962518b
BLAKE2b-256 625847a32098f98c6c57a6847dbab2771f49c78475a651103892f8ec4fd0f132

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page