API Reference
Working with Projects (RefiProject)
Handler for REFI-QDA Project (.qdpx) files.
A .qdpx file is a zipped archive containing a primary XML project file
and optional external sources (like PDFs or media).
Source code in pyrefiqda/refiproject.py
10 11 12 13 14 15 16 17 18 19 20 21 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 195 196 197 198 199 200 | |
import_source_file(local_file_path, extract_dir, source_guid=None)
staticmethod
Copies a local file into the project's sources directory and returns its REFI-QDA internal URI.
This method ensures full compliance with the REFI-QDA standard by copying the file
into a sources/ subfolder and renaming it to a unique GUID while preserving
the original file extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_file_path
|
str | Path
|
The path to the raw media/text file you want to add to the project. |
required |
extract_dir
|
str | Path
|
The temporary working directory for your project. |
required |
source_guid
|
str | None
|
(Optional) A specific GUID to use. If None, a new UUID4 is generated. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The properly formatted REFI-QDA internal URI (e.g., |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the provided |
Example
from pyrefiqda import RefiProject
internal_uri = RefiProject.import_source_file(
"raw_data/interview1.docx",
"./working_dir"
)
print(internal_uri) # Output: internal://b5566006-eb5f-43f0...docx
Source code in pyrefiqda/refiproject.py
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 195 196 197 198 199 200 | |
load(file_path, extract_dir='./extracted_qdpx')
staticmethod
Unzips a .qdpx file and parses the internal XML into Pydantic models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
The path to the existing |
required |
extract_dir
|
str
|
The directory where the zipped archive will be extracted. Defaults to "./extracted_qdpx". |
'./extracted_qdpx'
|
Returns:
| Name | Type | Description |
|---|---|---|
Project |
Project
|
The strictly-typed Pydantic Project model containing all qualitative data. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the provided |
Example
from pyrefiqda import RefiProject
project = RefiProject.load("study.qdpx", extract_dir="./temp_extract")
Source code in pyrefiqda/refiproject.py
17 18 19 20 21 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 | |
resolve_source_path(internal_path, extract_dir)
staticmethod
Resolves a REFI-QDA internal path to an actual local file path.
REFI-QDA projects store media and text files inside a sources/ directory
and reference them using an internal:// URI scheme. This helper translates
that URI into a usable Python Path object pointing to the extracted file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
internal_path
|
str
|
The REFI-QDA internal URI string (e.g., |
required |
extract_dir
|
str | Path
|
The local directory where the |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The resolved local filesystem path pointing to the source file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided |
Example
from pyrefiqda import RefiProject
project = RefiProject.load("research.qdpx", extract_dir="./temp_project")
# Analyze transcripts
for source in project.sources.text_source:
# Use helper to find the actual file on the hard drive
local_path = RefiProject.resolve_source_path(
source.plain_text_path,
"./temp_project"
)
with open(local_path, "r", encoding="utf-8") as f:
transcript_text = f.read()
print(transcript_text)
Source code in pyrefiqda/refiproject.py
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 | |
save(project, file_path, source_media_dir=None)
staticmethod
Serializes a Project Pydantic model back to XML and packages it into a .qdpx zip archive.
This method handles the standard compression required by the REFI-QDA specification, ensuring it can be opened by NVivo, MAXQDA, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
The populated Pydantic Project model. |
required |
file_path
|
str | Path
|
The destination path where the .qdpx file will be saved. |
required |
source_media_dir
|
str | Path | None
|
(Optional) The local directory containing the source files
(e.g., PDFs, images) that need to be packaged into the archive's |
None
|
Raises:
| Type | Description |
|---|---|
IOError
|
If there is an issue writing to the destination path. |
Example
from pyrefiqda import RefiProject
RefiProject.save(my_project, "project.qdpx")
Source code in pyrefiqda/refiproject.py
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 | |
Working with Codebooks (RefiCodebook)
Handler for standalone REFI-QDA Codebook (.qdc) files.
Unlike .qdpx projects, .qdc files are plain XML files used strictly
for exchanging coding hierarchies without media sources.
Source code in pyrefiqda/reficodebook.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 | |
load(file_path)
staticmethod
Parses a REFI-QDA Codebook (.qdc) XML file into a Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
The path to the existing |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CodeBook |
CodeBook
|
The strictly-typed Pydantic CodeBook model. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the provided |
Example
from pyrefiqda import RefiCodebook
codebook = RefiCodebook.load("initial_codes.qdc")
Source code in pyrefiqda/reficodebook.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
save(codebook, file_path)
staticmethod
Serializes a CodeBook Pydantic model back to XML and saves it as a .qdc file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codebook
|
CodeBook
|
The populated Pydantic CodeBook model. |
required |
file_path
|
str | Path
|
The destination path where the |
required |
Example
from pyrefiqda import RefiCodebook
RefiCodebook.save(my_codebook, "updated_codes.qdc")
Source code in pyrefiqda/reficodebook.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |