New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

magicalimport

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magicalimport

importing a module by physical file path

  • 0.9.1
  • PyPI
  • Socket score

Maintainers
1

magicalimport

.. image:: https://travis-ci.org/podhmo/magicalimport.svg?branch=master :target: https://travis-ci.org/podhmo/magicalimport

Importing a module from physical file path.

examples

these files are existed, then..

.. code-block:: bash

$ tree . ├── a │   └── b │   └── c │   └── foo.py └── main.py

4 directories, 3 files

a/b/c/foo.py

.. code-block:: python

name = "foo" _age = "secret"

.. code-block:: python

from magicalimport import import_from_physical_path

importing foo.py as the module named foo2

foo = import_from_physical_path("./a/b/c/foo.py", as_="foo2") print(foo.name)

cached in sys.modules, so it is ok.

import foo2 print(foo2.name)

here option ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

from magicalimport import import_from_physical_path

import_from_physical_path("bar.py", here="/tmp/foo", as_="bar")

star import ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

from magicalimport import import_from_physical_path from magicalimport import expose_all_members

something of like a from foo import *

expose_all_members(import_from_physical_path("./a/b/c/foo.py")) print(name) # "foo"

print(age) # NameError.. because expose_all_members() doesn't expose the symbols started by ""

or

from magicalimport import expose_members expose_members(import_from_physical_path("./a/b/c/foo.py"), members=["_age"]) print(_age) # "secret"

0.9.1

  • import_module() and import_symbol()'s cwd is True

0.9.0

0.8.1

  • cwd option

0.8.0

  • default behaviour is changed, from now, if here option is omitted, treated as here=__file__ on caller module.
  • ( previous behaviour is here=os.getcwd() )

0.7.3

  • skip needless init.py creation, in some cases

0.7.2

  • fix directly import module handling is not enough, now, treated as a same module

0.7.1

  • fix permission error, and same file, treated as a same module

0.7.0

  • fix same file, treated as a same module

0.6.0

  • fix module_id is not stored in sys.modules, on exec_module()

0.5.0

  • raised exception adjustment

0.3.0

  • ns option in import_symbol

0.2.1

  • here option is supported

0.2

  • python2 support

0.1

  • first release

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc