# pyportal
**Dependable Imports for Your Ever-Changing Scripts.**
Working with constantly changing Python scripts poses a unique challenge: how do you maintain reliable imports? The answer is `pyportal`. This innovative tool enables you to **lock in** on a specific version of your script, ensuring that future changes won't disrupt your dependencies. With `pyportal`, you're free to innovate and iterate your scripts while keeping other projects stable and dependable.
## Examples
**Example 1: Simple Import** You can use `pyportal` to import the latest version of the `say_hello` function from `myutils.py`. This will always import `say_hello` from the most recent commit (as the suffix `.latest` suggests).
```python
# This is your original script file `myutils.py`
def say_hello():
print('hello')
# Now you want to use it in another place:
import pyportal
from pyportal.myutils.latest import say_hello
# Using the function
say_hello() # prints: hello
```
**Example 2: Version-specific Import** With the `.v` suffix, `pyportal` can import a specific version of a function. Even though `myutils.py` has been modified, you can still access the old version of `say_hello` thanks to `pyportal`.
```python
# Assume that you have modified `myutils.py` and it now looks like this:
def say_hello():
print('hello, world!')
# But you still want the old version in another place:
import pyportal
# v20230103192241 is a version identifier, 'v' followed by the datetime of the specific git commit
from pyportal.myutils.v20230103192241 import say_hello
# Using the function
say_hello() # prints: hello
```
**Example 3: Managing Multiple Script Versions** `pyportal` allows you to manage and use multiple versions of a script within the same project. By importing different versions of the `say_hello` function under different names, you can use the version that suits your needs in each part of your project.
```python
# Assume that you have multiple versions of `myutils.py` and you want to use different versions in different places:
import pyportal
# Importing a specific version, again using the datetime of the commit as the version identifier
from pyportal.myutils.v20230103192241 import say_hello as old_hello
old_hello() # prints: hello
```
**Example 4: Importing Like Standard Python Imports** With the `.file` suffix, you can import whatever is currently in the script file with `pyportal`. It works just like the standard Python import. This is particularly useful for testing out your scripts. But be aware, you must commit your changes to be able to lock in on them, as shown in Example 2.
```python
# Assume that you have multiple versions of `myutils.py` and you want to use different versions in different places:
import pyportal
# Importing a specific version, again using the datetime of the commit as the version identifier
from pyportal.myutils.v20230103192241 import say_hello as old_hello
old_hello() # prints: hello
```
## How to use
**Install the package**
```
pip install pyportal
```
**Import syntax**
You must import the `pyportal` package first. Then you can import a specific version of a script.
For example, you have a folder with the following structure
```python
# /utility_scripts/myutil.py
def foo():
pass
###
# In any python script on your computer
import pyportal
# add script folder
pyportal.path.insert(0, "/utility_scripts")
# Import from script myutil.py
from pyportal.myutil.file import foo
# OR import the whole script
import pyportal.myutil.file as Util
# OR import everything
from pyportal.myutil.file import *
```
Package statement follows the syntax `pyportal.<name_of_scriptfile>.<version>` (e.g., `pyportal.myutil.latest`). It always has three components, separated by dots.
1. `pyportal`. The name of the package.
2. `<name_of_scriptfile>`. The file name of your script, *no space allowed*. `pyportal` searches in order of specified folders (see the setup guide below), and returns the first result. Try not to have scripts under the same name.
3. `<version>`. Specify the version of the script to import from. Can be one of
1. `file`. Import the file on disk just like the standard Python import.
2. `vyyyymmddHHMMSS`. Import a specific version to lock in. It is a `v` followed by the datetime of the git commit in yyyymmddHHMMSS (year month day hour minutes seconds) format.
**Setup script folders**
Working like Python imports, `pyportal` searches for the requested script by its file name in the given folders. You can set the folders globally in the environment variable `pyportal_PATH`. For example, we add a folder under C drive named `my scripts`, and another folder named `PythonScripts` under our Documents folder. In all OS systems, you need to separate multiple folders by a `semicolon`. Note that the order of folders matters. If you have two script files with the same name, the one that appeared first in the folders will be used.
```cmd
pyportal_PATH=C:\my scripts;C:\Document\PythonScripts
```
You can also modify the path `pyportal` searches by manipulating its `path` attribute:
```python
import pyportal
# modify the path list and add a new folder to search for scripts
pyportal.path.append('D:/new script')
# import a constant from a script located at D:/new script/foo.py
from pyportal.foo.file import pi
print(pi)
# prints 3.14
```
Raw data
{
"_id": null,
"home_page": "https://github.com/alanyue/pyportal",
"name": "pyportal",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "import python scripts git version control",
"author": "Alan Yue",
"author_email": "alanyue@example.com",
"download_url": "https://files.pythonhosted.org/packages/10/e0/b6cfacf7280fd54593bc2d6160f4c078fb6143e52145b4d36da329a59607/pyportal-1.0.1.tar.gz",
"platform": null,
"description": "# pyportal\r\n\r\n**Dependable Imports for Your Ever-Changing Scripts.**\r\n\r\n\r\nWorking with constantly changing Python scripts poses a unique challenge: how do you maintain reliable imports? The answer is `pyportal`. This innovative tool enables you to **lock in** on a specific version of your script, ensuring that future changes won't disrupt your dependencies. With `pyportal`, you're free to innovate and iterate your scripts while keeping other projects stable and dependable.\r\n\r\n\r\n## Examples\r\n\r\n**Example 1: Simple Import** You can use `pyportal` to import the latest version of the `say_hello` function from `myutils.py`. This will always import `say_hello` from the most recent commit (as the suffix `.latest` suggests).\r\n\r\n```python\r\n# This is your original script file `myutils.py`\r\ndef say_hello():\r\n print('hello')\r\n\r\n# Now you want to use it in another place:\r\nimport pyportal\r\nfrom pyportal.myutils.latest import say_hello\r\n\r\n# Using the function\r\nsay_hello() # prints: hello\r\n```\r\n\r\n**Example 2: Version-specific Import** With the `.v` suffix, `pyportal` can import a specific version of a function. Even though `myutils.py` has been modified, you can still access the old version of `say_hello` thanks to `pyportal`.\r\n\r\n```python\r\n# Assume that you have modified `myutils.py` and it now looks like this:\r\ndef say_hello():\r\n print('hello, world!')\r\n\r\n# But you still want the old version in another place:\r\nimport pyportal\r\n\r\n# v20230103192241 is a version identifier, 'v' followed by the datetime of the specific git commit\r\nfrom pyportal.myutils.v20230103192241 import say_hello\r\n\r\n# Using the function\r\nsay_hello() # prints: hello\r\n```\r\n\r\n**Example 3: Managing Multiple Script Versions** `pyportal` allows you to manage and use multiple versions of a script within the same project. By importing different versions of the `say_hello` function under different names, you can use the version that suits your needs in each part of your project.\r\n\r\n```python\r\n# Assume that you have multiple versions of `myutils.py` and you want to use different versions in different places:\r\nimport pyportal\r\n\r\n# Importing a specific version, again using the datetime of the commit as the version identifier\r\nfrom pyportal.myutils.v20230103192241 import say_hello as old_hello\r\nold_hello() # prints: hello\r\n```\r\n\r\n\r\n**Example 4: Importing Like Standard Python Imports** With the `.file` suffix, you can import whatever is currently in the script file with `pyportal`. It works just like the standard Python import. This is particularly useful for testing out your scripts. But be aware, you must commit your changes to be able to lock in on them, as shown in Example 2.\r\n\r\n```python\r\n# Assume that you have multiple versions of `myutils.py` and you want to use different versions in different places:\r\nimport pyportal\r\n\r\n# Importing a specific version, again using the datetime of the commit as the version identifier\r\nfrom pyportal.myutils.v20230103192241 import say_hello as old_hello\r\nold_hello() # prints: hello\r\n```\r\n\r\n## How to use\r\n\r\n**Install the package**\r\n\r\n```\r\npip install pyportal\r\n```\r\n\r\n**Import syntax**\r\n\r\nYou must import the `pyportal` package first. Then you can import a specific version of a script.\r\n\r\nFor example, you have a folder with the following structure\r\n\r\n```python\r\n# /utility_scripts/myutil.py\r\ndef foo():\r\n pass\r\n\r\n###\r\n\r\n# In any python script on your computer\r\nimport pyportal\r\n# add script folder\r\npyportal.path.insert(0, \"/utility_scripts\")\r\n\r\n# Import from script myutil.py\r\nfrom pyportal.myutil.file import foo\r\n# OR import the whole script\r\nimport pyportal.myutil.file as Util\r\n# OR import everything\r\nfrom pyportal.myutil.file import *\r\n```\r\n\r\nPackage statement follows the syntax `pyportal.<name_of_scriptfile>.<version>` (e.g., `pyportal.myutil.latest`). It always has three components, separated by dots.\r\n\r\n1. `pyportal`. The name of the package.\r\n2. `<name_of_scriptfile>`. The file name of your script, *no space allowed*. `pyportal` searches in order of specified folders (see the setup guide below), and returns the first result. Try not to have scripts under the same name.\r\n3. `<version>`. Specify the version of the script to import from. Can be one of\r\n 1. `file`. Import the file on disk just like the standard Python import.\r\n 2. `vyyyymmddHHMMSS`. Import a specific version to lock in. It is a `v` followed by the datetime of the git commit in yyyymmddHHMMSS (year month day hour minutes seconds) format.\r\n\r\n\r\n**Setup script folders**\r\n\r\nWorking like Python imports, `pyportal` searches for the requested script by its file name in the given folders. You can set the folders globally in the environment variable `pyportal_PATH`. For example, we add a folder under C drive named `my scripts`, and another folder named `PythonScripts` under our Documents folder. In all OS systems, you need to separate multiple folders by a `semicolon`. Note that the order of folders matters. If you have two script files with the same name, the one that appeared first in the folders will be used.\r\n\r\n```cmd\r\npyportal_PATH=C:\\my scripts;C:\\Document\\PythonScripts\r\n```\r\n\r\nYou can also modify the path `pyportal` searches by manipulating its `path` attribute:\r\n\r\n```python\r\nimport pyportal\r\n# modify the path list and add a new folder to search for scripts\r\npyportal.path.append('D:/new script')\r\n# import a constant from a script located at D:/new script/foo.py\r\nfrom pyportal.foo.file import pi\r\nprint(pi) \r\n# prints 3.14\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Import Python script from any directory or git commit history.",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/alanyue/pyportal"
},
"split_keywords": [
"import",
"python",
"scripts",
"git",
"version",
"control"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "42b6a5e7c1db38c2caec5f1312c1f6fc29fb6b05e6997a1fcde5e17a905e9f85",
"md5": "877f5bdf457427c2ec95fbdda514e5c2",
"sha256": "1df758cbc8d1b837d7659258fb620714a839253afffa081418a32c2122b3b320"
},
"downloads": -1,
"filename": "pyportal-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "877f5bdf457427c2ec95fbdda514e5c2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7382,
"upload_time": "2025-09-13T02:33:08",
"upload_time_iso_8601": "2025-09-13T02:33:08.082251Z",
"url": "https://files.pythonhosted.org/packages/42/b6/a5e7c1db38c2caec5f1312c1f6fc29fb6b05e6997a1fcde5e17a905e9f85/pyportal-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "10e0b6cfacf7280fd54593bc2d6160f4c078fb6143e52145b4d36da329a59607",
"md5": "906dcb835124d32d4e629c119b1ff0b0",
"sha256": "26ccbd3872e2d9314d85fab12d1e53dc4df6ab074608ee47c4af637d99299731"
},
"downloads": -1,
"filename": "pyportal-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "906dcb835124d32d4e629c119b1ff0b0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8746,
"upload_time": "2025-09-13T02:33:09",
"upload_time_iso_8601": "2025-09-13T02:33:09.172680Z",
"url": "https://files.pythonhosted.org/packages/10/e0/b6cfacf7280fd54593bc2d6160f4c078fb6143e52145b4d36da329a59607/pyportal-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-13 02:33:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alanyue",
"github_project": "pyportal",
"github_not_found": true,
"lcname": "pyportal"
}