├── setup.cfg ├── tests ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-313.pyc │ └── test_core.cpython-313-pytest-8.3.4.pyc └── test_core.py ├── .gitignore ├── src └── cqd │ ├── __init__.py │ ├── __pycache__ │ ├── core.cpython-313.pyc │ └── __init__.cpython-313.pyc │ └── core.py ├── assets ├── example.png └── example2.png ├── pyproject.toml ├── LICENSE └── README.md /setup.cfg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | dist/ -------------------------------------------------------------------------------- /src/cqd/__init__.py: -------------------------------------------------------------------------------- 1 | from .core import cqd, cqd2 2 | 3 | __version__ = "0.1.1" 4 | -------------------------------------------------------------------------------- /assets/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayking99/cqd/HEAD/assets/example.png -------------------------------------------------------------------------------- /assets/example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayking99/cqd/HEAD/assets/example2.png -------------------------------------------------------------------------------- /src/cqd/__pycache__/core.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayking99/cqd/HEAD/src/cqd/__pycache__/core.cpython-313.pyc -------------------------------------------------------------------------------- /tests/__pycache__/__init__.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayking99/cqd/HEAD/tests/__pycache__/__init__.cpython-313.pyc -------------------------------------------------------------------------------- /src/cqd/__pycache__/__init__.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayking99/cqd/HEAD/src/cqd/__pycache__/__init__.cpython-313.pyc -------------------------------------------------------------------------------- /tests/__pycache__/test_core.cpython-313-pytest-8.3.4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayking99/cqd/HEAD/tests/__pycache__/test_core.cpython-313-pytest-8.3.4.pyc -------------------------------------------------------------------------------- /tests/test_core.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from cqd import cqd, cqd2 3 | 4 | 5 | class TestClass: 6 | def __init__(self): 7 | self.public_attr = 1 8 | self._protected_attr = 2 9 | 10 | 11 | def test_cqd_function(capsys): 12 | obj = TestClass() 13 | cqd(obj) 14 | captured = capsys.readouterr() 15 | assert "__init__" in captured.out 16 | assert "_protected_attr" in captured.out 17 | assert "public_attr" in captured.out 18 | 19 | 20 | def test_cqd2_function(capsys): 21 | obj = TestClass() 22 | cqd2(obj) 23 | captured = capsys.readouterr() 24 | assert "__init__" in captured.out 25 | assert "_protected_attr" in captured.out 26 | assert "public_attr" in captured.out 27 | assert "int" in captured.out 28 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [project] 6 | name = "cqd" 7 | version = "0.1.1" 8 | authors = [ 9 | { name = "Jason Pickup", email = "therayking99@gmail.com" } 10 | ] 11 | description = "cqd - A colorful object attribute inspector" 12 | readme = "README.md" 13 | requires-python = ">=3.6" 14 | classifiers = [ 15 | "Programming Language :: Python :: 3", 16 | "License :: OSI Approved :: MIT License", 17 | "Operating System :: OS Independent", 18 | "Development Status :: 4 - Beta", 19 | "Intended Audience :: Developers", 20 | "Topic :: Software Development :: Debuggers", 21 | ] 22 | 23 | [project.urls] 24 | "Homepage" = "https://github.com/rayking99/cqd" 25 | "Bug Tracker" = "https://github.com/rayking99/cqd/issues" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 JSO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cqd 2 | 3 | A lightweight Python utility that provides colored visualization of object attributes, making it easier to inspect objects during development and debugging. 4 | 5 | ## Features 6 | 7 | - Color-coded attribute display: 8 | - 🔵 Blue: Dunder methods 9 | - 🟡 Yellow: Protected attributes (starting with `_`) 10 | - 🟢 Green: Public attributes and methods 11 | 12 | For example - here is a snippet of the tokenizer from huggingface. 13 | 14 | example 15 | 16 | ## Installation 17 | 18 | You can install the package using pip: 19 | 20 | ``` 21 | pip install cqd 22 | ``` 23 | 24 | ## Usage 25 | 26 | To use the `cqd` function, import it from the package: 27 | 28 | ```python 29 | from cqd import cqd 30 | 31 | # Example usage 32 | cqd(your_object) 33 | ``` 34 | 35 | If you want to see the types, use cqd2 36 | 37 | ```python 38 | from cqd import cqd2 as q 39 | import math 40 | 41 | q(math) 42 | 43 | ``` 44 | 45 | That will produce: 46 | 47 | ![alt text](assets/example2.png) 48 | 49 | ## Contributing 50 | 51 | Feel free to submit issues or pull requests for improvements or bug fixes. 52 | 53 | ## License 54 | 55 | This project is licensed under the MIT License. 56 | -------------------------------------------------------------------------------- /src/cqd/core.py: -------------------------------------------------------------------------------- 1 | def cqd(obj): 2 | # ANSI color codes 3 | BLUE = "\033[94m" 4 | YELLOW = "\033[93m" 5 | GREEN = "\033[92m" 6 | RESET = "\033[0m" 7 | attributes = dir(obj) 8 | for attr in attributes: 9 | if attr.startswith("__") and attr.endswith("__"): # Dunder methods 10 | print(f"{BLUE}{attr}{RESET}") 11 | elif attr.startswith("_"): # Protected attributes 12 | print(f"{YELLOW}{attr}{RESET}") 13 | else: # Public attributes or methods 14 | print(f"{GREEN}{attr}{RESET}") 15 | 16 | 17 | def cqd2(obj): 18 | # ANSI color codes 19 | BLUE = "\033[94m" 20 | YELLOW = "\033[93m" 21 | GREEN = "\033[92m" 22 | RESET = "\033[0m" 23 | 24 | attributes = dir(obj) 25 | for attr in attributes: 26 | try: 27 | # Get the attribute value and its type 28 | attr_value = getattr(obj, attr) 29 | attr_type = type(attr_value).__name__ 30 | 31 | if attr.startswith("__") and attr.endswith("__"): # Dunder methods 32 | print(f"{BLUE}{attr:<30} : {attr_type}{RESET}") 33 | elif attr.startswith("_"): # Protected attributes 34 | print(f"{YELLOW}{attr:<30} : {attr_type}{RESET}") 35 | else: # Public attributes or methods 36 | print(f"{GREEN}{attr:<30} : {attr_type}{RESET}") 37 | except Exception: 38 | # Handle cases where attribute access might be restricted 39 | print(f"{attr:<30} : ") 40 | --------------------------------------------------------------------------------