typerdrive Files modules
typerdrive.files.attach
Provide a decorator that attaches the typerdrive files to a typer command function.
Attributes
Classes
Functions
attach_files
Attach the typerdrive files to the decorated typer command function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show
|
bool
|
If set, show the files directory after the function runs. |
False
|
Source code in src/typerdrive/files/attach.py
get_files_manager
Retrieve the FilesManager from the TyperdriveContext.
Source code in src/typerdrive/files/attach.py
typerdrive.files.commands
Provide commands that can be added to a typer app to interact with files.
Classes
Functions
add_files_subcommand
Add all files subcommands to the given app.
add_show
typerdrive.files.exceptions
Provide exceptions specific to the files feature of typerdrive.
Classes
FilesClearError
Bases: FilesError
Indicate that there was a problem deleting a file.
Source code in src/typerdrive/files/exceptions.py
FilesError
Bases: TyperdriveError
The base exception for files errors.
Source code in src/typerdrive/files/exceptions.py
FilesInitError
Bases: FilesError
Indicate that there was a problem initializing the files storage.
Source code in src/typerdrive/files/exceptions.py
FilesLoadError
Bases: FilesError
Indicate that there was a problem loading a file.
Source code in src/typerdrive/files/exceptions.py
FilesStoreError
Bases: FilesError
Indicate that there was a problem storing a file.
Source code in src/typerdrive/files/exceptions.py
typerdrive.files.manager
Provide a class for managing the typerdrive files feature.
Classes
FilesManager
Manage the typerdrive files feature.
This manager provides a simple key-value file storage system where files are stored in a directory structure. Files can be stored as bytes, text, or JSON and retrieved the same way.
Source code in src/typerdrive/files/manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
Attributes
Functions
__init__
delete
Delete a file at the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file key where the file should be deleted |
required |
Source code in src/typerdrive/files/manager.py
list_items
List files at a given path.
Items will be all non-directory entries in the given path.
If the path doesn't exist or is not a directory, an exception will be raised.
Source code in src/typerdrive/files/manager.py
load_bytes
Load binary data from a file at the given key.
If there is no file at the given key, an exception will be raised. If there is an error reading the file, an exception will be raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file key where the data should be loaded from |
required |
Source code in src/typerdrive/files/manager.py
load_json
Load a dictionary from a JSON file at the given key.
The file at the given key must be valid JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file key where the JSON should be loaded from |
required |
Source code in src/typerdrive/files/manager.py
load_text
Load text from a file at the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file key where the text should be loaded from |
required |
resolve_path
Resolve a given file key path to an absolute path within the files directory.
If the resolved path is outside the files directory, an exception will be raised. If the resolved path is the same as the files directory, an exception will be raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file key |
required |
mkdir
|
bool
|
If set, create the directory for the file key if it does not exist. |
False
|
Source code in src/typerdrive/files/manager.py
store_bytes
Store binary data as a file at the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The binary data to store |
required |
path
|
Path | str
|
The file key where the data should be stored |
required |
mode
|
int | None
|
The file mode to use when creating the file |
None
|
Source code in src/typerdrive/files/manager.py
store_json
Store a dictionary as a JSON file at the given key.
The dictionary must be json serializable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The dict to store as JSON |
required |
path
|
Path | str
|
The file key where the JSON should be stored |
required |
mode
|
int | None
|
The file mode to use when creating the file |
None
|
Source code in src/typerdrive/files/manager.py
store_text
Store text as a file at the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to store |
required |
path
|
Path | str
|
The file key where the text should be stored |
required |
mode
|
int | None
|
The file mode to use when creating the file |
None
|