Treat a GitHub repo files as a Python object.
Project description
Dynamic Prompt Importer
Dynamic Prompt Importer turns a GitHub repository full of Markdown files into a Python object. Each prompt can be accessed as an attribute which lazily downloads the file on first use. The package was born out of laziness—I wanted a quick way to pull prompts from my private prompt repo without manually copying files around.
Installation
Install from PyPI:
pip install dynamic-prompt-importer
For development install the repo directly:
pip install -e .
Usage
from dynamic_prompt_importer import DynamicPromptImporter
importer = DynamicPromptImporter(
"owner/my-prompt-repo", # GitHub "owner/repo" spec
token="ghp_yourGitHubToken", # needed for private repos
preload=True, # fetch the repo tree immediately
)
text = importer.get_file_content("folder/welcome")# contents of folder/welcome.md
Creating a GitHub token for private repositories
You only need a personal access token when accessing a private repository. The recommended approach is to create a fine-grained token with read-only access to the specific repo that stores your prompts.
- Verify your GitHub email address if you have not done so already.
- Click your profile picture in the upper-right corner of GitHub and choose Settings.
- In the left sidebar select Developer settings.
- Under Personal access tokens click Fine-grained tokens and then Generate new token.
- Give the token a name and expiration and optionally add a description.
- Choose the resource owner and repository that the token should access, then select the minimal permissions required (read-only is sufficient here). Readonly for the content is enough
- Click Generate token and copy the resulting value.
Note that GitHub limits each account to 50 fine-grained tokens. For larger automation needs consider creating a GitHub App instead.
Use this token for the token parameter when instantiating
DynamicPromptImporter.
API
DynamicPromptImporter(repo, token=None, branch="main", preload=False)- create an importer for a GitHub repo.- Attribute access mirrors the repository structure:
importer.docs.setupreturns the text ofdocs/setup.md. get_file_content(path)- retrieve a file via an explicit path.reload()- clear caches and re-fetch the repository tree.
Why?
Maintaining prompts in a separate repository keeps them version controlled and editable without redeploying application code. This utility lets you pull those prompts into Python on demand so that your code always uses the latest version.
Running Tests
pytest -vv -s
The tests use mocked HTTP responses so no network access is required. A JSON
summary will be written to test_report.json after the run. See
tests/README.md for more details on what each test covers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynamic_file_importer-0.1.3.tar.gz.
File metadata
- Download URL: dynamic_file_importer-0.1.3.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6be319051fccf4895a890df8423be183c2c5629250303f053cca1fabbd110cd3
|
|
| MD5 |
0e8fec53775cb0ff90dcc98737634541
|
|
| BLAKE2b-256 |
27562842e756282e65e93ab285112b5e8f23ac7f29d1bd89401cd7de59b86b7a
|
File details
Details for the file dynamic_file_importer-0.1.3-py3-none-any.whl.
File metadata
- Download URL: dynamic_file_importer-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e35f4503a49475b7bec3aab1edf87839688b9191e6d2399fdf601d712ebaed7
|
|
| MD5 |
ad70fd67f3cfc7c3cfea68097cbc0405
|
|
| BLAKE2b-256 |
6a655b430df6e823874b3fb4c27d84b5f6b8991b7cdd7909f2c866d6c99bd1fa
|