Pyosphere
A hack to enable easy and error-free imports in Python.
Install / Use
/learn @vedantpuri/PyosphereREADME
Pyosphere
Python projects that have complex codebase directory structures introduce a fairly common problem with imports within the project. While providing absolute paths is recommended, it is cumbersome, repetitive, and rather boilerplate. Absolute imports may also decrease application portability. pyosphere.sh mitigates these issues by simply providing a flattened execution environment, allowing all files to relatively import each other trivially, while allowing developers to maintain their choice of directory structure.
Requirements
- macOS or Linux
- Bash >= 3.2 (lower versions untested)
Installation
pyosphere.sh can be installed or deployed in many ways:
Homebrew
Install with homebrew:
brew tap vedantpuri/concoctions
brew install pyosphere
Manual System Install
For macOS, you can install from the repo directly:
curl -s "https://api.github.com/repos/vedantpuri/pyosphere/releases/latest" | grep '"browser_download_url":' | sed -E 's/.*"([^"]+)".*/\1/' | xargs curl -L -s -0 > pyosphere && mv pyosphere /usr/local/bin/ && chmod 700 /usr/local/bin/pyosphere && chmod +x /usr/local/bin/pyosphere
Linux users may prefer replacing /usr/local/bin/ to ~/bin/ (requires curl, sed, grep, and xargs):
mkdir -p ~/bin && curl -s "https://api.github.com/repos/vedantpuri/pyosphere/releases/latest" | grep '"browser_download_url":' | sed -E 's/.*"([^"]+)".*/\1/' | xargs curl -L -s -0 > pyosphere && mv pyosphere ~/bin/ && chmod 700 ~/bin/pyosphere && chmod +x ~/bin/pyosphere
You can also download specific versions to your project:
cd ~/path/to/project
curl -L -s "https://github.com/vedantpuri/pyosphere/releases/download/1.1.2/pyosphere.sh" > pyosphere.sh && chmod +x pyosphere.sh
Alternatively, download pyosphere.sh and make it executable:
cd ~/path/to/downloaded/script
chmod +x pyosphere.sh
Usage
pyosphere.sh is designed to be as simple as possible to use. It has 2 aspects:
- "pyosphere" directory - created in your project directory when the script genreates a build
- "pyosphere.config" file - can be generated using the script that specifies a configuation for the build
Step 1
Navigate to your python project.
cd ~/path/to/project
Step 2
To build and run with default pyosphere settings:
pyosphere
Initialize pyosphere in this project.
pyosphere -i
Auto-generates pyosphere.config in your project with default settings, and does not build/execute.
or
pyosphere -ie="python_file_to_be_executed"
Auto-generates pyosphere.config in your project with specified file as run_source. Does not build/execute.
Step 3
By default, pyosphere.sh auto-detects configuration files if they use the default naming scheme. You can specify the config file yourself, although you must ensure that it is a bash script:
# auto-detect configuration (pyosphere.config)
pyosphere
# If filename is different
pyosphere -cf="myconfig.config"
# You can use any extension for this file, or none
pyosphere -cf="myconfig"
Options
-
Initialize pyosphere (
Generate a default pyosphere.config file in current directory-i|--init) -
Initialize Execution (
Initialize pyosphere in current dir and specify which python file to run in configuration file-ie=|--init-exec=) -
Configuration (
Specify path to configuration file-cf=|--config-file=) -
Prune project (
Remove unused project files from future builds-p|--prune) -
Clean project (
Clean pyosphere build-cl|--clean) -
Reset project (
Reset project to its state prior to use of pyosphere-r|--reset) -
Silent (
Silence pyosphere echo messages while executing project-s|--silent) -
Version (
Print script version-v|--version) -
Help (
Print script usage-h|--help)
You can tune the following options in your configuration file:
-
python_bin (default =
Specify python binary to use (such as python, python3, or their full paths)python) -
project_path (default =
Specify project path if differentpwd) -
always_prune (default =
Specify preference to prune (false)-p|--prune) every build -
run_source
Specify python file to run on executing build -
resources_to_include
Specify file extensions other than .py that are required by your code
E.g.resources_to_include=("txt" "png" "pdf")
Your code would be able to directly access these files from$PROJECT_ROOT/pyosphere
Not providing one or more of these fields is acceptable and default settings will be inferred in such cases.
Use Cases
Consider a multi-directory project with your custom library:
- src
- hello_world.py
- test.py
- lib
- frameworks
- test_framework.py
- test_utils.py
- some_lib
- some_lib_program.py
- frameworks
Suppose that while working in test.py, you decide that you need test_framework.py. Ordinarily, you would:
# depends on where you are executing from
path_to_test_framework = "..."
import path_to_test_framework/test_framework.py
It can be cumbersome to specify a specific or even relative path to a different .py file. If pyosphere is the primary execution mechanism:
import test_framework.py
will work seamlessly, without manipulating directory structure. Additional resources such as .txt files or the like will also be handled if specified in pyosphere's configuration.
Limitations
Due to the semantics of the script it fails to work as expected in projects which have:
- Multiple files with the same name
- Hard-coded file paths (use
os.pathinstead to generalize)
Contributing
This is an open-source project and contribution is cordially welcome. Refer to contribution guidelines for further details on how to contribute. Also be sure to view the code of conduct.
License
The project is available under the MIT License. Check out the license file for more information.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
92.1kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
343.3kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
