What Are the Available Output Formats for a `Result` Object in user-scanner?
The Result class in user-scanner supports eight distinct output formats: JSON, CSV, clean dictionary, raw dictionary, integer status code, console output, debug string, and string representation—each exposed through dedicated methods.
The Result class serves as the central data container for every scan operation in the kaifcodec/user-scanner repository. Understanding what output formats a Result object supports is essential for integrating scan data into pipelines, exporting results, or customizing CLI displays. All formatting logic is implemented in user_scanner/core/result.py, with factory helpers available in user_scanner/core/orchestrator.py.
JSON Output with to_json()
The to_json() method serializes a Result to a pretty-printed JSON string. It delegates to to_dict() for data preparation, then applies json.dumps with indentation.
from user_scanner.core.orchestrator import Result
res = Result.taken(
username="alice",
site_name="GitHub",
category="social",
url="https://github.com/alice",
extra={"followers": 42},
media={"avatar": "https://avatars.githubusercontent.com/u/1?v=4"},
)
json_str = res.to_json()
print(json_str)
Source code reference: user_scanner/core/result.py lines 96-100.
CSV Output with to_csv()
The to_csv() method produces a single CSV row compatible with the global CSV_FIELDS header. It flattens nested extra and media dictionaries and neutralizes Excel formula triggers for security.
csv_row = res.to_csv()
print(csv_row)
This format is ideal for bulk export and spreadsheet analysis. Source code reference: user_scanner/core/result.py lines 200-224.
Dictionary Outputs: Clean vs. Raw
Clean Dictionary: to_dict()
The to_dict() method returns a cleaned dictionary ready for JSON or external export. It strips the internal is_email flag and renames username to email when the result represents an email lookup.
clean_dict = res.to_dict()
print(clean_dict)
Source code reference: user_scanner/core/result.py lines 84-92.
Raw Dictionary: as_dict()
The as_dict() method exposes the full internal state, including is_email and raw url fields. Use this for debugging or custom processing where internal metadata matters.
raw_dict = res.as_dict()
print(raw_dict)
Source code reference: user_scanner/core/result.py lines 71-82.
Integer Status Code with to_number()
The to_number() method encodes status as compact integers:
| Value | Constant | Meaning |
|---|---|---|
| 0 | TAKEN |
Username/email exists |
| 1 | AVAILABLE |
Username/email is free |
| 2 | ERROR |
Scan failed |
| 3 | SKIPPED |
Scan bypassed |
status_code = res.to_number()
print(status_code) # Output: 0
Source code reference: user_scanner/core/result.py lines 52-54.
Human-Readable Outputs
Console Output: get_console_output()
The get_console_output() method generates colored, icon-prefixed strings as shown in the CLI. It appends the target URL when verbose mode is enabled through ScanConfig.
print(res.get_console_output())
Source code reference: user_scanner/core/result.py lines 54-86.
Debug String: debug()
The debug() method returns a multiline representation with all fields for developer inspection.
print(res.debug())
Source code reference: user_scanner/core/result.py lines 93-95.
String Representation: __str__()
When printed directly, a Result falls back to __str__(), which outputs the plain reason text or an empty string.
print(res) # Prints reason text
Source code reference: user_scanner/core/result.py lines 26-28.
Complete Usage Example
from user_scanner.core.orchestrator import Result, Status
# Create sample result
res = Result.taken(
username="alice",
site_name="GitHub",
category="social",
url="https://github.com/alice",
extra={"followers": 42},
media={"avatar": "https://avatars.githubusercontent.com/u/1?v=4"},
)
# All output formats
print("JSON:", res.to_json())
print("CSV:", res.to_csv())
print("Clean dict:", res.to_dict())
print("Raw dict:", res.as_dict())
print("Status code:", res.to_number())
print("Console:", res.get_console_output())
print("Debug:", res.debug())
print("String:", str(res))
Key Source Files
| File | Purpose |
|---|---|
user_scanner/core/result.py |
Implements Result class and all output format methods |
user_scanner/core/orchestrator.py |
Factory helpers (Result.taken, Result.available, etc.) |
user_scanner/core/helpers.py |
ScanConfig class influencing console output behavior |
Summary
- Eight output formats cover machine-readable export (JSON, CSV, dict, number) and human display (console, debug, string)
to_json()andto_csv()are the primary export methods for data pipelinesto_dict()vs.as_dict()offer clean export versus full internal state accessto_number()enables compact storage withTAKEN=0,AVAILABLE=1,ERROR=2,SKIPPED=3- Console and debug outputs serve CLI and development workflows respectively
Frequently Asked Questions
What is the difference between to_dict() and as_dict() in user-scanner?
to_dict() returns a cleaned dictionary for export, stripping internal flags like is_email and normalizing field names. as_dict() exposes the complete internal state including raw URLs and boolean flags—use it for debugging or when you need unprocessed data.
Which Result output format should I use for Excel compatibility?
Use to_csv(). It produces a single row matching the CSV_FIELDS header and sanitizes cell content to prevent Excel formula injection attacks.
How does to_number() encode status information?
It maps status constants to integers: TAKEN=0, AVAILABLE=1, ERROR=2, SKIPPED=3. This enables compact database storage and fast numeric comparisons without string parsing.
Can I customize the console output colors and icons?
Indirectly, yes. The get_console_output() method respects configuration from ScanConfig (defined in user_scanner/core/helpers.py), which controls verbosity and can influence URL appending behavior. Direct color/icon customization requires modifying the source in user_scanner/core/result.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →