Giter Club home page Giter Club logo

httpimport's Introduction

httpimport

Python's missing feature!

Remote, in-memory Python package/module importing through HTTP/S

Downloads

PyPI - Python Version PyPI version Python package

CPython 3 Pypy 3.6

A feature that Python misses and has become popular in other languages is the remote loading of packages/modules.

httpimport lets Python packages and modules to be installed and imported directly in Python interpreter's process memory, through remote URIs, and more...

Python2 support has been discontinued. Last version that supports Python2 is 1.1.0.

Basic Usage

Load package/module accessible through any HTTP/S location

with httpimport.remote_repo('http://my-codes.example.com/python_packages'):
  import package1

Load a module from PyPI:

with httpimport.pypi_repo():
  import distlib # https://pypi.org/project/distlib/

print(distlib.__version__)
# '0.3.6' <-- currently latest (https://github.com/pypa/distlib/blob/0.3.6/distlib/__init__.py#L9)

Load directly from a GitHub/BitBucket/GitLab repo

with httpimport.github_repo('operatorequals', 'httpimport', ref='master'):
  import httpimport as httpimport_upstream
  # Also works with 'bitbucket_repo' and 'gitlab_repo'

Load a Python module from a Github Gist (using this gist):

url = "https://gist.githubusercontent.com/operatorequals/ee5049677e7bbc97af2941d1d3f04ace/raw/e55fa867d3fb350f70b2897bb415f410027dd7e4"

with httpimport.remote_repo(url):
  import hello

hello.hello()
# Hello world

Load a package/module directly to a variable

# From HTTP/S URL
http_module = httpimport.load('package1', 'https://my-codes.example.com/python_packages')
print(http_module)
<module 'package1' from 'https://my-codes.example.com/python_packages/package1/__init__.py'>

# From PyPI
pypi_module = httpimport.load('distlib', importer_class=httpimport.PyPIImporter)
print(pypi_module)
<module 'distlib' from 'https://files.pythonhosted.org/packages/76/cb/6bbd2b10170ed991cf64e8c8b85e01f2fb38f95d1bc77617569e0b0b26ac/distlib-0.3.6-py2.py3-none-any.whl#distlib/__init__.py'>

Load Python packages from archives served through HTTP/S

No file is touching the disk in the process

# with httpimport.remote_repo('https://example.com/packages.tar'):
# with httpimport.remote_repo('https://example.com/packages.tar.bz2'):
# with httpimport.remote_repo('https://example.com/packages.tar.gz'):
# with httpimport.remote_repo('https://example.com/packages.tar.xz'):
with httpimport.remote_repo('https://example.com/packages.zip'):
  import test_package

Serving a package through HTTP/S

Any package can be served for httpimport using a simple HTTP/S Server:

echo 'print("Hello httpimport!")' > module.py
python -m http.server
Serving HTTP on 0.0.0.0 port 8000 ...
>>> import httpimport
>>> with httpimport.remote_repo("http://127.0.0.1:8000"):
...   import module
...
Hello httpimport!

Profiles

After v1.0.0 it is possible to set HTTP Authentication, Custom Headers, Proxies and several other things using URL and Named Profiles!

URL Profiles

URL Profiles are INI configurations, setting specific per-URL options, as below:

[http://127.0.0.1:8000]
allow-plaintext: yes ; also 'true' and '1' evaluate to True

[https://example.com]
proxy-url: https://127.0.0.1:8080 ; values must not be in quotes (')

Now, requests to http://127.0.0.1:8000 will be allowed (HTTP URLs do not work by default) and requests to https://example.com will be sent to an HTTP Proxy.

with httpimport.remote_repo("https://example.com"): # URL matches the URL profile
  import module_accessed_through_proxy

Named Profiles

Named Profiles are like URL profiles but do not specify a URL and need to be explicitly used:

[github]
headers:
  Authorization: token <Github-Token>

And the above can be used as follows:

with httpimport.github_repo('operatorequals','httpimport-private-test', profile='github'):
  import secret_module
Github Tokens look like github_pat_<gibberish> and can be issued here: https://github.com/settings/tokens/new

Profiles for PyPI

When importing from PyPI extra options can be used, as described in the profile below:

[pypi]

# The location of a 'requirements.txt' file
# to use for PyPI project versions
requirements-file: requirements-dev.txt

# Inline 'requirements.txt' syntax appended
requirements:
  distlib==0.3.5
  sampleproject==3.0.0

# Only version pinning notation is supported ('==')
# with 'requirements' and 'requirements-file' options

# A map that contains 'module': 'PyPI project' tuples
# i.e: 'import sample' --> search 'sample' module at 'sampleproject' PyPI Project:
# https://pypi.org/project/sampleproject/
project-names:
  sample: sampleproject

The PyPI Profiles can be used exactly like all Named Profiles:

with httpimport.pypi_repo(profile='pypi'):
  import distlib
  import sample
distlib.__version__
# '0.3.5' <-- pinned in the profile 'requirements' option
sample.__url__
# 'https://files.pythonhosted.org/packages/ec/a8/5ec62d18adde798d33a170e7f72930357aa69a60839194c93eb0fb05e59c/sampleproject-3.0.0-py3-none-any.whl#sample/__init__.py' <-- loaded from 'sampleproject'

Additionally, all other options cascade to PyPI profiles, such as HTTPS Proxy (HTTP proxies won't work, as PyPI is hosted with HTTPS), headers, etc.

NOTE: The values in Profiles MUST NOT be quoted (',")

Profile Creation

Profiles can be provided as INI strings to the set_profile function and used in all httpimport functions:

httpimport.set_profile("""
[profile1]

proxy-url: https://my-proxy.example.com
headers:
  Authorization: Basic ...
  X-Hello-From: httpimport
  X-Some-Other: HTTP header
""")
with httpimport.remote_repo("https://code.example.com", profile='profile1'):
  import module_accessed_through_proxy

Advanced

Profiles are INI configuration strings parsed using Python configparser module.

The ConfigParser object for httpimport is the global variable httpimport.CONFIG and can be used freely:

import httpimport
httpimport.CONFIG.read('github.ini') # Read profiles from a file

with httpimport.github_repo('operatorequals','httpimport-private-test', profile='github'):
  import secret_module

Default Profiles

The httpimport module automatically loads Profiles found in $HOME/.httpimport.ini and under the $HOME/.httpimport/ directory. Profiles under $HOME/.httpimport/ override ones found in $HOME/.httpimport.ini.

Profile Options:

Supported

HTTP options

  • zip-password - v1.0.0
  • proxy-url - v1.0.0
  • headers - v1.0.0
  • allow-plaintext - v1.0.0
  • ca-verify - v1.3.0
  • ca-file - v1.3.0

PyPI-only options

  • project-names - v1.2.0
  • requirements - v1.2.0
  • requirements-file - v1.2.0

Not yet (subject to change)

  • allow-compiled

  • auth

  • auth-type

  • tls-cert

  • tls-key

  • tls-passphrase

Debugging...

import httpimport
import logging

logging.getLogger('httpimport').setLevel(logging.DEBUG)

Beware: Huge Security Implications!

Using the httpimport with plain HTTP URLs is highly discouraged

As HTTP traffic can be read and changed from all intermediate hosts (unlike HTTPS), it is possible for a remote adversary to alter the HTTP responses consumed by httpimport and add arbitrary Python code to the downloaded packages/modules. This directly results in arbitrary Remote Code Execution on your current user's context of your host!

In other words, using plain HTTP through the Internet can compromise your host without a way to notice it.

You have been warned! Use only HTTPS URLs with httpimport!

Contributors

  • ldsink - The RELOAD flag and Bug Fixes
  • lavvy - the load() function
  • superloach - Deprecation of imp module in Python3 in favour of importlib
  • yanliakos - Bug Fix
  • rkbennett - Relative Imports fix, Proxy support

Donations

In case my work helped you, you can always buy me a beer or a liter of gas through the Internet or in case you meet me personally.

In the second case we can talk about any video of Internet Historian or Ordinary Things, while listening to a Lofi Girl Playlist, like the citizens of the Internet that we are.

donation

httpimport's People

Contributors

kolibril13 avatar lavvy avatar ldsink avatar operatorequals avatar rkbennett avatar yanliakos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httpimport's Issues

Relative Path Importing/incorrect import package

This is heavily related to #28, though I believe they were half way incorrect when they said importing a second time would result in a working execution. Based on what I've seen, when the import fails it ends up in a half-way state where the import isn't shown in globals() or dir(), but can be seen from sys.modules(). This breaks some stuff and likely won't result in an actually working function/module.

Took some time to dig into this issue and it's not actually an issue with relative path imports, that's more of a symptom, the actual issue stems from the fact that nested modules don't get the proper value set for their __package__ attribute.

This is caused by line 224 in the current code where, no matter what the path is, it splits it and grabs the first item in the index and uses that as the package. So a for example:

Package1_
         |_Module1
         |_Package2_
                    |_Module2
                    |_Module3

If you have the following file structure and Module3 contains 'import .Module2' that will fail, because python uses the __package__ attribute to determine relative paths and all of these modules have Package1 as their __package__.

AttributeError - unlcear how to import a Class from a module

unable to get followig imported https://github.com/rosomri/atlassian-python-api imported via

with httpimport.github_repo('rosomri', 'atlassian-python-api', ref='confluence_bugfix_export_pdf'):
import atlassian

Traceback (most recent call last):
File "C:\develop\git\scripts\collectors\confluence.py", line 213, in
confluence = connect_to_confluence(args.cf_url, args.cf_user, args.cf_token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\develop\git\scripts\collectors\confluence.py", line 48, in connect_to_confluence
return atlassian.Confluence(
^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'atlassian' has no attribute 'Confluence'

What i am doing wrong?

Add pure logging for HTTP/S requests

This is quite self explanatory.
It is quite useful to have a log of all the requests made by this module, maybe by a different logger than the httpimport one:

req_logger = logging.getLogger("httpimport.requests")

so it can have all kinds of controls like, log to file, colors, etc.

When debugging, or when working with network issues this could be a useful tool.

Code to import from gist now breaks with AttributeError: 'list' object has no attribute 'endswith'

Thanks for this wonderful package. Until recently, I could use the following code to load a module from a gist:

url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"

with httpimport.remote_repo(["Gmodel"], url):
    from Gmodel import GProblem

After updating various modules, it now it fails with AttributeError: 'list' object has no attribute 'endswith' - not sure what changed and how I can work around this ...

Importing libraries with different installation name

When we want to import cv2 library It shows module not found error.
I know that we need to install it by opencv-python but we can't use the statement "import opencv-python".
How to import the libraries that have a different name in usage and installation. Which one to use.
If we can set it in the profile settings how to do it?

What does modules parameter is used for?

self.module_names = modules

For my case, the codes below also work though I didn't specify modules

import httpimport
url = "https://gist.githubusercontent.com/zhqu1148980644/435304b90d1511099b070414c760e968/raw/e388a5ba1e3580eb9f4cb9e3061ab1f47210cf94"
with httpimport.remote_repo([], url):
       import task
task.task1("asdasd")

No module named 'somePython' when using remote_repo

I can't seem to get remote_repo to work. I've tried accessing modules in my private Gitlab instance and an example module in Github. I keep getting "No module named x" error. I assume it has something to do with my code but I've tried a few different iterations with no luck. It would be nice to see a working example in the readme that pulls from a publicly available python package. The load() method also can't seem to find the module.

Here's a snippet.

#!/usr/bin/env python3
from httpimport import remote_repo
import httpimport
with remote_repo(['myPackage'], 'https://github.com/BillMills/python-package-example/blob/master/myPackage/'):
    import somePython

BitBucket Direct Support

Given that the URLs of the raw files in a BitBucket repo follows the format:

https://bitbucket.org/{user}/{repo_name}/raw/{commit_hash/branch_name}/{directory/}*{file_name}

a bitbucket_repo() context can be created, similar to already implemented github_repo().
Arguments can be exactly the same as in github_repo():

  • username
  • repo name
  • branch/commit

can't access private repo from github

Hi, I ran the code:

import httpimport
profile = """
[github]
headers:
  Authorization: token ghp_WjewI0mwxxxxxxxxxxxxxxxxez9"""

httpimport.set_profile(profile)

with httpimport.github_repo('myid', 'myrepo', profile='github'):
    import mypkg

but it gave ModuleNotFoundError.
could you please test with this function, and maybe make more instruction for us?

Not supported from package.module import class

with httpimport.github_repo('operatorequals','covertutils'):
    from covertutils.handlers import BaseHandler
ImportError: cannot import name 'BaseHandler' from 'covertutils.handlers' (https://raw.githubusercontent.com/operatorequals/covertutils/master/covertutils/handlers/__init__.py)

httpimport version: 1.3.0

Dropbox support

Hi! httpimport is ok with GitHub, it would be useful to have also Dropbox support. But it is not fundamental.
Thank you for your support John,
Bye

Add support for module import directly from PyPI

There can be a function suite that directly search PyPI (through the API) and loaded sdist or wheel packages directly.
Also, versions can be set as function parameters, or even a requirements.txt file.

Deprecation of imp.new_module

Since Python 3.4, many methods of the imp package, including imp.new_module, are deprecated.

I've been using imp.new_module myself in a side-project and I was curious if you had solved this problem. new_module is still working, but as it's an implementation detail, it might or might not disappear.

Python3 support ?

I couldn't help but notice that covertutils is python2 only, is it the same for httpimport ?
Any plan for python3 ?

I am also interested in similar topics, doing distributed software development in python, and I maintain a python 2/3 compatibility package for custom importers, in case it helps : https://github.com/asmodehn/filefinder2

Support for Gitlab private repos

Hi there,
this is very neat, would be fantastic to find a way to also support private gitlab/github maybe via an ssh key?
Cheers!

Python 3.12 Support

Starting in python 3.12 the find_module has been removed in favor of find_spec. The load_module function has also been deprecated in favor of the create_module and exec_module functions respectively. In order for this project to continue working for the latest python, these functions will need added. I have implemented them in my remote import hook package I wrote from the ground up if you want some ideas as to how this could be implemented. My repo is at od_import.

GitLab Direct Support

Given that the URLs of the raw files in a GitLab repo follows the format:

https://gitlab.com/{user}/{repo_name}/raw/{commit_hash/branch_name}/{directory/}*{file_name}

a gitlab_repo() context can be created, similar to already implemented github_repo().
Arguments can be exactly the same as in github_repo():

  • username
  • repo name
  • branch/commit

The context can be tested with the below Python project:
https://gitlab.com/BananenBernd/basictools

Authenticated Requests to Github, GitLab, BitBucket

As of now, httpimport works for only public repositories.

For developers in companies, enterprise environments, and generally people that work in private repositories a method is needed to remotely load packages/modules from private repos.

So this ticket addresses the integration of such methods (as per design and implementation) into the [github|gitlab|bitbucket]_repo methods:


  • GitHub

    • Design
    • Implementation
  • BitBucket

    • Design
    • Implementation
  • GitLab

    • Design
    • Implementation

The ticket will be updated for Design decisions and for accepted implementations for each of the platforms, with mentions to answers and commits.

".pyc" file support

It is highly possible, that a package/module contains the .pyc (python compiled) files in the HTTP/S repo/directory. This could happen, if the package/module has been run/imported, at least once, locally.
Yet the httpimport module, as is, looks only for .py files.

There can be a modification/flag/optional argument, that enables the Importer class to look for .pyc files and strip their contents to make them executable. This can be done, as these files include the output of compile() Python function, and the output of compile() can be used with exec function/statement.

This will probably enhance loading time!

Remove "modules" parameter from functions and HttpImporter

The modules parameter was used to declare what packages/modules can be imported from a certain URL.
This parameter was being used so the importer wouldn't try requests for modules that didn't exist at the "find_module" phase. This was done to not generate useless traffic. Minimal traffic was a functional requirement of this project in previous versions, as it was a RAT stager

Now, it is possible to try requests for commands in dynamic ways, hence the whole positional parameter can be omitted in a version change that changes the interface of:

HttpImporter
remote_repo
add_remote_repo

PyPIImporter should be able to use proxy

Reading through your documentation you say you've disable HTTP_PROXY for pypi because it's an HTTPS request. I may have missed the code change, but if you're still using ProxyHandler, that isn't related to the HTTP_PROXY and HTTPS_PROXY variables which I believe you're referencing in your README. ProxyHandler with work with proxied requests to both http and https sites.

Add remote repos in python command line arguments

Starting a Python process with preinstalled remote repos would be useful. Something like the following:

$ python -m httpimport --insecure github://operatorequals/covertutils http://somerepo:8000/python-packages
[...]
>>> import covertutils
>>>

For this issue to be implemented, Issue 21 has to be implemented first, to not declare what packages should be implemented from given URLs.

import public github

Hello,
I am not sure what I am doing wrong but this should work right?v

with httpimport.github_repo('priamai','stixorm',ref='master'):
  import stixorm
  from stixorm.module.typedb import TypeDBSink,TypeDBSource

I am getting an:


ImportError: cannot import name 'TypeDBSink' from 'stixorm.module.typedb' (https://raw.githubusercontent.com/priamai/stixorm/master/stixorm/module/typedb.py)


---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

uses of httpimport

Hi! First of all thank you for your library.
John can you please confirm that httpimport works with remote libraries and packages only if:

  • these remote libraries/packages are full (inside the folder 'master' user finds all the external required libraries) or

  • all the dependencies (external required libraries) are already installed properly in the python environment?

An other question is: if I want to import a remote library/package named "A" that requires some external packages not available inside the 'master' folder of "A" (for example the one I sent you, fipy), can I create an alternative library/package named "A_full" with inside all the external required libraries/packages (pure-python or not-pure python like *.dll, *.so, *.a, *.lib, ... ) in order to be able to import all without doing 'pip install ...' before using httpimport with lib "A"?

A simpler example: if remote lib "A" requires a remote lib "B" with a different url from "A", httpimport can't import "A" because httpimport can't know where to search for "B" in internet. But if I add lib "B" inside the master folder of "A" creating a github clone of the lib "A" + lib "B", is it possible to use httpimport with the cloned lib "A"?

I do mostly scientific computation with Python and sometimes I use a remote server that offers a full python environment with a lot of useful math packages (https://sagecell.sagemath.org/). Sometimes I need some packages not installed in the remote server, so it would be very useful to import temporary these packages with a remote importer via web (user can't install with pip any library in the server, user has only RAM and CPU time for each calculation).

Thank you!
Regards
Matteo

Support ".zip" file importing

It would be great to support zip'd Python packages. There is already a built-in functionality with ZipImporter, but it needs the .zip file to be on disk (listable and with a filename).

Support for .zip has to be in-memory only.

It is possible that the example code below will be useful:

https://stackoverflow.com/questions/39135750/python-load-zip-with-modules-from-memory

How to disable own httpimport logging? (or raise its level)

My first use case for httpimport was a logging library common to several scripts:

# toconsole.py

import logging
import os

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(message)s')
handler_console = logging.StreamHandler()
level = logging.DEBUG if 'DEV' in os.environ else logging.INFO
handler_console.setLevel(level)
handler_console.setFormatter(formatter)
log.addHandler(handler_console)

# disable httpimport logging except for errors+
logging.getLogger('httpimport').setLevel(logging.ERROR)

A simple usage such as

import httpimport

httpimport.INSECURE = True
with httpimport.remote_repo(['githublogging'], 'http://localhost:8000/') :
    from toconsole import log

log.info('yay!')

gives the following output

[!] Using non HTTPS URLs ('http://localhost:8000//') can be a security hazard!
2019-08-25 13:56:48,671 yay!
yay!

The second (bare) yay! must be coming from httpimport, namely from its logging setup.

How can I disable httpimport logging, or better - raise its level so that only errors+ are logged? The logging.getLogger('httpimport').setLevel(logging.ERROR) I tried did not work.

Support Gitea Service

Gitea is a self-hostable Modern Git Service. It shares many features with Gitlab, Github and the rest, such as HTTP raw file download. Thous it can be supported by httpimport

A gitea_repo can be implemented by formatting URLs such as the one below (taken from Gitea's Swagger page):

https://try.gitea.io/test/test/raw/branch/master/README.md

Httpimport as a class

I have tried to rewrite this module as a class but with no luck. But somehow i believe it would be possible.
If the module can be converted to a class it would more awesome.
E. G.
a = httpimport()
b = a.import(foo)
c = b(new_func)

Can not import file from package

I have run that code but i have error in importing

this is my repo link

and this is my code

with httpimport.github_repo('AKHACKER-program4hack', 'searcher', branch='master'):
    import searcher.forsearch
    s = forsearch.Searcher()
    s.printuser()

And i am getting this error:

Traceback (most recent call last):
  File "/home/ak/Desktop/development/pythonwork/testing/httpimport/testing.py", line 8, in <module>
    s = forsearch.Searcher()
NameError: name 'forsearch' is not defined

Can anyone tell me what's the problem

Problem: Relative Path Importing

If you attempt to do the following in a httpimport'd file

from .file import classname

it results in the error

ImportError: cannot import name 'classname' from package.file
File "/usr/local/lib/python3.7/dist-packages/httpimport.py", line 254, in load_module
    exec(final_src, mod.__dict__)
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/httpimport.py", line 254, in load_module
    exec(final_src, mod.__dict__)
  File "<string>", line 26, in <module>
  File "/usr/local/lib/python3.7/dist-packages/httpimport.py", line 254, in load_module
    exec(final_src, mod.__dict__)
  File "<string>", line 1, in <module>

https://www.python.org/dev/peps/pep-0328/

Yet....

if you import again right after it fails... it imports correctly....

attribute error module 'passman' has no attribute 'list_profiles'

I am unable to determine whether the library in my gitlab repo is getting picked up; Its not throwing any errors. But when I try to access the function in from the imported module its saying that attribute does not exist. Any way for me to access the httpimporter class variables to check whats going on?

Test.py

import httpimport
with httpimport.remote_repo("https://gitlab.mycompany.com/dz/co_library/"):
    import passman

print(dir(passman))
print(passman.__url__)
print(passman.list_profiles())

when I run the script to test it, im not seeing any of the function inside of passman.py and I get the following error:

['__builtins__', '__doc__', '__file__', '__loader__', '__package__', '__path__', '__spec__', '__url__']
https://gitlab.mycompany.com/dz/co_library/passman.py
Traceback (most recent call last):
   File "Test.py", line 6, in <module>
     print(passman.list_profiles()
AttributeError: module 'passman' has no attribute 'list_profiles'

init.py from co_library

from . import *

setup.py from co_library

from setuptools import setup, find_packages

setup(name="co_library", 
    version="0.1.0",
    packages=["passman",],
    py_modules=["passman",],
    )

New version 0.9.2 breaks loading of joblib pickled model

Firstly, thank you for the project - I think it's amazing and shall be advertised wider. It's part of my secret sauce to deploy AI/ML models into distributed systems.
I used version 0.7.2 to load a pickled pre-trained Automata (Trie structure)

import httpimport
with httpimport.remote_repo(['utils'], "https://raw.githubusercontent.com/applied-knowledge-systems/the-pattern-automata/main/automata/"):
    import utils
from utils import loadAutomata, find_matches

with cryptic stack trace:

[!] 'nt' not found in HTTP repository. Moving to next Finder.
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/home/alex/anaconda3/envs/thepattern_3.7/lib/python3.7/site-packages/httpimport.py", line 232, in load_module
    exec(module_src, mod.__dict__)
  File "<string>", line 36, in <module>
  File "<string>", line 5, in loadAutomata
  File "/home/alex/anaconda3/envs/thepattern_3.7/lib/python3.7/site-packages/joblib/__init__.py", line 113, in <module>
    from .memory import Memory, MemorizedResult, register_store_backend
  File "/home/alex/anaconda3/envs/thepattern_3.7/lib/python3.7/site-packages/joblib/memory.py", line 15, in <module>
    import pathlib
  File "/home/alex/anaconda3/envs/thepattern_3.7/lib/python3.7/pathlib.py", line 4, in <module>
    import ntpath
  File "/home/alex/anaconda3/envs/thepattern_3.7/lib/python3.7/ntpath.py", line 257, in <module>
    from nt import _getvolumepathname
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 640, in _load_backward_compatible
KeyError: 'nt'

I went on a path debugging joblib, but actual loading works:

import ahocorasick 
import joblib
Automata=joblib.load("automata_fresh_semantic.pkl.lzma")

full code for loading https://github.com/applied-knowledge-systems/the-pattern-automata/blob/main/automata/utils.py`
Code for creating automata is simple and hosted in the same repo: https://github.com/applied-knowledge-systems/the-pattern-automata

I am reverting to 0.7.2, but any suggestions for uplifting are welcome.

Problem in Google Colab

Hi, I am trying to import from gist in a google collab:

import httpimport
url = "https://gist.githubusercontent.com/ricardofrantz/96ee9d9fc253c2af30b0b9d6405f35ef/raw/2de95ca2d5b7b51aa2a3cfc6f248bc46eb9980d7"
with httpimport.remote_repo(url):
    import diff_matrix as df
L = df.diff_matrix()
print(L)

it seems there is some blockage in the ambient... is there a known way to bypass it?

WARNING:httpimport:[!] Using non HTTPS URLs ('http://localhost:8000//') can be a security hazard!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================
DEBUG:httpimport:[!] Searching diff_matrix
DEBUG:httpimport:[!] Path is None
INFO:httpimport:[@] Checking if in declared remote module names >
INFO:httpimport:[-] Not found!
DEBUG:httpimport:FINDER=================

ModuleNotFoundError Traceback (most recent call last)
in
2 url = "https://gist.githubusercontent.com/ricardofrantz/96ee9d9fc253c2af30b0b9d6405f35ef/raw/2de95ca2d5b7b51aa2a3cfc6f248bc46eb9980d7"
3 with httpimport.remote_repo(url):
----> 4 import diff_matrix as df
5 L = df.diff_matrix()
6 print(L)

ModuleNotFoundError: No module named 'diff_matrix'


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

Thanks for your help,
Ricardo

Importing non-packages?

I have a large number of non-package(i.e. single file) libraries to pull in. The documentation seems to focus a lot on packages. Is there a way to pull them in without converting them to packages?

Proxy Support

HTTP/S Proxy Support might be useful in case a host cannot directly connect to the Web.
It could be implemented by just passing a proxy list to a Global Variable PROXY_LIST like follows:

import httpimport
httpimport.PROXY_LIST=[
  ('127.0.0.1', 8080),    # Some Burp Installation?
  ('randomhttpproxy.org',80),
 ]

Support packages with shared object files

Not sure if this is something that's feasible, but there are multiple packages that required .so files to work, such as psutil. Is there a possibility of supporting packages like that? I understand there are implications with matching architecture and what not, but unless I'm missing something (entirely possible), there's no way to import a package like that currently.

"pip_load" function and PyPI support

Given that the module will gain support for tar.* files (Issue #16), a function can be implemented that directly fetches tarballs from pypi.org, visiting the imported module's page, such as https://pypi.org/project//#files.
This page contains download links for all versions of module, that are not statically constructed. These links can be followed to download the tarball and later import it.

So a function pip_load can have the below signature:

def pip_load(module, version="latest"):
[...]

Additionally, a context can be created, named pip() or pip_repo, directly importing to memory from PyPI, with the below usage:

with pip():
  import module_in_pip

Finally, a function can be created that can parse requirements.txt files and directly load the dependencies using calls to pip_load or translating to pip() context commands.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.