<@ULVA73B9P> how can i create Local File System an...
# ask-marvin
o
@Marvin how can i create Local File System and GitHub Credentials blocks with python?
m
thought for 224.7 seconds
Here’s how to create and save those blocks in Python (Prefect 3.x): 1) Install the GitHub integration
Copy code
pip install prefect-github
2) Create and save a Local File System block
Copy code
from prefect.filesystems import LocalFileSystem

# Point this to the directory you want Prefect to use
local_fs = LocalFileSystem(basepath="/path/on/this/machine")
local_fs.save("my-local-fs", overwrite=True)
3) Create and save a GitHub Credentials block
Copy code
from prefect_github.credentials import GitHubCredentials

gh_creds = GitHubCredentials(token="ghp_your_personal_access_token")
gh_creds.save("my-github-creds", overwrite=True)
4) Load and use them later
Copy code
from prefect.filesystems import LocalFileSystem
from prefect_github.credentials import GitHubCredentials

local_fs = LocalFileSystem.load("my-local-fs")
gh_creds = GitHubCredentials.load("my-github-creds")

# Optional: quick check that local_fs works
local_fs.write_path("test.txt", b"hello")
print(local_fs.read_path("test.txt"))
Notes - You must be connected to your Prefect backend (Cloud or a running server) to save blocks. - Use
overwrite=True
if you want to update an existing block with the same name. - The GitHub token is stored as a secret and will be masked in the UI/logs. Docs - Blocks overview: Prefect 3 Blocks - File systems API: LocalFileSystem API - GitHub integration: prefect-github