Skip to main content

Treat a GitHub repo files as a Python object.

Project description

Dynamic File 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-file-importer

For development install the repo directly and then run:

pip install -e .

Usage

from dynamic_file_importer import DynamicFileImporter

importer = DynamicFIleImporter(
    "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.md")
text = importer.get_file_content("folder/welcome.json") 

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 DynamicFileImporter.

API

  • DynamicFileImporter(repo, token=None, branch="main", preload=False) - create an importer for a GitHub repo.
  • get_file_content(path/file.json or file.md etc) - retrieve a file via an explicit path.
  • reload() - clear caches and re-fetch the repository tree. **Haven't tested yet **

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.5.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.5-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file dynamic_file_importer-0.1.5.tar.gz.

File metadata

  • Download URL: dynamic_file_importer-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 cd86d53a9dd4a1faa4477573f68ca43166b3e46c8642425c2d391d6a88d1dac2
MD5 25135e408c35901dac399f4de54596b4
BLAKE2b-256 14edda00962c1f413e11785be4f3af538d0c589ec7bc471f9b79bc120a5e52c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamic_file_importer-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d1f58390e09b76bf6ea81c0ebfed0adb2992b0aeae843195f0c74fdc349f0572
MD5 4127dad82a82be23caee805e8d23249d
BLAKE2b-256 5e77b16126cd73b714e85287dc2dedb7c253be63a2fa043b79e8c8da6368644d

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