Skip to main content

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.

  1. Verify your GitHub email address if you have not done so already.
  2. Click your profile picture in the upper-right corner of GitHub and choose Settings.
  3. In the left sidebar select Developer settings.
  4. Under Personal access tokens click Fine-grained tokens and then Generate new token.
  5. Give the token a name and expiration and optionally add a description.
  6. 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
  7. 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.setup returns the text of docs/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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamic_file_importer-0.1.3.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamic_file_importer-0.1.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for dynamic_file_importer-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6be319051fccf4895a890df8423be183c2c5629250303f053cca1fabbd110cd3
MD5 0e8fec53775cb0ff90dcc98737634541
BLAKE2b-256 27562842e756282e65e93ab285112b5e8f23ac7f29d1bd89401cd7de59b86b7a

See more details on using hashes here.

File details

Details for the file dynamic_file_importer-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamic_file_importer-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e35f4503a49475b7bec3aab1edf87839688b9191e6d2399fdf601d712ebaed7
MD5 ad70fd67f3cfc7c3cfea68097cbc0405
BLAKE2b-256 6a655b430df6e823874b3fb4c27d84b5f6b8991b7cdd7909f2c866d6c99bd1fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page