dirmapper-core


Namedirmapper-core JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryCore library for directory mapping and summarization
upload_time2024-12-21 02:26:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2024 nashdean Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords directory mapping summarization
VCS
bugtrack_url
requirements requests openai pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dirmapper-core
A directory mapping library that aids in visualization and directory structuring.
# dirmapper-core

A directory mapping library that aids in visualization and directory structuring.

## Features

- Generate directory structures in various styles (tree, list, flat, etc.)
- Apply custom formatting to directory structures (plain text, JSON, HTML, Markdown, etc.)
- Ignore specific files and directories using patterns
- Summarize directory contents using AI (local or API-based)

## Installation

To install the library, use pip:

```sh
pip install dirmapper-core
```

## Usage
### Generating Directory Structure
You can generate a directory structure using the `DirectoryStructureGenerator` class. Here is an example:
```python
# Example usage

from dirmapper_core.generator.directory_structure_generator import DirectoryStructureGenerator
from dirmapper_core.ignore.path_ignorer import PathIgnorer
from dirmapper_core.styles.tree_style import TreeStyle
from dirmapper_core.formatter.formatter import PlainTextFormatter

# Define ignore patterns
ignore_patterns = [
    SimpleIgnorePattern('.git/'),
    SimpleIgnorePattern('.github/'),
    SimpleIgnorePattern('__pycache__/')
]

# Initialize PathIgnorer
path_ignorer = PathIgnorer(ignore_patterns)

# Initialize DirectoryStructureGenerator
generator = DirectoryStructureGenerator(
    root_dir='./path/to/your/directory',
    output='output.txt',
    ignorer=path_ignorer,
    sorting_strategy=AscendingSortStrategy(case_sensitive=False),
    style=TreeStyle(),
    formatter=PlainTextFormatter()
)

# Generate the directory structure into the style specified when initializing DirectoryStructureGenerator
structure = generator.generate() # Returns str
```
Generating a directory structure results in a formatted string depending on your style and formatter. Here is an example of the `TreeStyle`:
```
/path/to/root/directory
├── requirements.txt
├── tests/
│   ├── test1.py
│   └── __init__.py
├── docs/
├── README.md
├── setup.py
├── .gitignore
├── src/
│   └── snake_game/
│       ├── __init__.py
│       ├── utils/
│       │   └── helper.py
│       └── main.py
```
See the [styles](dirmapper_core/styles) folder for all valid style examples.

You may also generate a raw DirectoryStructure object if you set the parameter `styled` to False in the `generate()` method. This allows access to the `DirectoryStructure` class helper functions and access to `DirectoryItems`
```python
# ...
structure = generator.generate(styled=False) # Returns DirectoryStructure object

# Access file content lazily
for item in structure.to_list():
    if item.metadata.get('content') is not None:
        print(f"Content of {item.path}: {item.content}")
```

### Creating Directory Structure from Template
You can create a directory structure from a template using the `StructureWriter` class. Here is an example:
```python
from dirmapper_core.writer.structure_writer import StructureWriter

# Define the base path where the structure will be created
base_path = 'Path/To/Your/Project'

# Define the structure template
structure_template = {
    "meta": {
        "version": "2.0",
        "source": "dirmapper",
        "author": "root",
        "root_path": base_path,
        "creation_date": "2024-11-01T20:06:14.510200",
        "last_modified": "2024-11-01T20:06:14.510211"
    },
    "template": {
        "requirements.txt": {},
        "tests/": {
            "test1.py": {},
            "__init__.py": {}
        },
        "docs/": {},
        "README.md": {},
        "setup.py": {},
        ".gitignore": {},
        "src/": {
            "snake_game/": {
                "__init__.py": {},
                "utils/": {
                    "helper.py": {}
                },
                "main.py": {}
            }
        }
    }
}

# Initialize StructureWriter
writer = StructureWriter(base_path)

# Create the directory structure
writer.create_structure(structure_template)

# Write the structure to OS file system
writer.write_structure()
```

### Writing Directory Structure to Template File
You can write the generated directory structure to a template file using the `write_template` function. Here is an example:
```python
from dirmapper_core.writer.template_writer import write_template

# Define the path to the template file
template_path = 'path/to/your/template.json'

# Define the structure template
structure_template = {
    "meta": {
        "version": "1.1",
        "source": "dirmapper",
        "author": "root",
        "root_path": template_path,
        "creation_date": "2024-11-01T20:06:14.510200",
        "last_modified": "2024-11-01T20:06:14.510211"
    },
    "template": {
        "requirements.txt": {},
        "tests/": {
            "test1.py": {},
            "__init__.py": {}
        },
        "docs/": {},
        "README.md": {},
        "setup.py": {},
        ".gitignore": {},
        "src/": {
            "snake_game/": {
                "__init__.py": {},
                "utils/": {
                    "helper.py": {}
                },
                "main.py": {}
            }
        }
    }
}

write_template(template_path, structure_template)
```
You may also use a valid styled directory string (i.e. `tree`) as your `structure_template` in the example above to write a YAML or JSON template file.

### Writing a Directory Structure Formatted String to Template
You can create a JSON template from a formatted directory structure string. Here is a valid example using the `tree` style:
```python
import json
from dirmapper_core.writer.template_parser import TemplateParser

tp = TemplateParser()
template = """
/path/to/root/directory
├── .git/
├── .github/
│   └── workflows/
│       ├── check_version.yaml
│       ├── publish.yaml
│       └── update-homebrew-formula.yml
├── .gitignore
├── .pytest_cache/
├── CHANGELOG.md
├── docs/
├── LICENSE
├── Makefile
├── pyproject.toml
├── README.md
├── requirements.txt
├── src/
│   └── dirmapper/
│       ├── __init__.py
│       ├── ai/
│       │   └── summarizer.py
│       ├── api_client.py
│       ├── config.py
│       ├── config_manager.py
│       ├── data/
│       │   └── .mapping-ignore
│       ├── main.py
│       ├── reader/
│       │   ├── __init__.py
│       │   └── reader.py
│       ├── token_manager.py
│       └── writer/
│           ├── __init__.py
│           └── writer.py
└── tests/
    ├── __init__.py
    └── test_main.py
"""
parsed_template = tp.parse_from_directory_structure(template)
print(json.dumps(parsed_template, indent=4))
```
Other allowable styles include `list`, `flat`, and `indentation`.

### Summarizing Directory Structure
You can summarize the directory structure using the `DirectorySummarizer` class. Here is an example:
```python
### Summarizing Directory Structure
from dirmapper_core.generator.directory_structure_generator import DirectoryStructureGenerator
from dirmapper_core.ai.summarizer import DirectorySummarizer
from dirmapper_core.models.directory_structure import DirectoryStructure
from dirmapper_core.models.directory_item import DirectoryItem
from dirmapper_core.styles.tree_style import TreeStyle

# Initialize DirectorySummarizer with configuration
config = {
    "use_local": False,
    "api_token": "your_openai_api_token",
    "summarize_file_content": True,  # Enable file content summarization
    "max_file_summary_words": 50     # Limit file summaries to 50 words
}

summarizer = DirectorySummarizer(config)

# Create a DirectoryStructure instance
root_dir = "path/to/root/project"
dsg = DirectoryStructureGenerator("path/to/root/project")
structure = dsg.generate(styled = False)

# Generate summaries
result = summarizer.summarize(structure)
print(json.dumps(result, indent=2))

# Nicely format your short summaries to the terminal
print(TreeStyle.write_structure_with_short_summaries(structure))
```

In the above example, you see that the __*result*__ from the `DirectorySummarizer` is a dict for easy JSON convertability. If you want to view the directory in a *tree* style, you can use the `write_structure_with_short_summaries` method which takes a DirectoryStructure object.

### Summarizing Files
You can summarize individual files using the `FileSummarizer` class. Here is an example.
```python
from dirmapper_core.ai.summarizer import FileSummarizer

preferences = {
    "use_local": False,
    "api_token": "your_openai_api_token_here"
}

file_summarizer = FileSummarizer(preferences)
file_path = "/path/to/your/file.py"
summary = file_summarizer.summarize_file(file_path, max_words=150)
print("File Summary:")
print(summary)
```

## Configuration
### Ignoring Files and Directories
You can specify files and directories to ignore using the .mapping-ignore file or by providing patterns directly to the PathIgnorer class.

Example `.mapping-ignore` file:
```
# Ignore .git directory
.git/
# Ignore all __pycache__ directories
regex:^.*__pycache__$
# Ignore all .pyc files
regex:^.*\.pyc$
# Ignore all .egg-info directories
regex:^.*\.egg-info$
# Ignore all dist directories
regex:^.*dist$
```

### Custom Styles and Formatters
You can create custom styles and formatters by extending the BaseStyle and Formatter classes, respectively.

## Appendix
### Working with DirectoryStructure Class
All styles and many functions work with the DirectoryStructure class under the hood. This class is essentially an abstracted list of DirectoryItem objects. Below is a sample usage of initializing, adding items, and converting to a specialized dictionary object.
```python
# Create a new DirectoryStructure instance
structure = DirectoryStructure()

# Add items to the structure
structure.add_item(DirectoryItem('/path/to/game', 0, 'game', {
    'type': 'folder',
    'content': None,
    'summary': None,
    'short_summary': None,
    'tags': []
}))

structure.add_item(DirectoryItem('/path/to/game/game_loop.py', 1, 'game_loop.py', {
    'type': 'file',
    'content': 'def main_loop():\n    while True:\n        update()\n        render()',
    'summary': None,
    'short_summary': None,
    'tags': []
}))

structure.add_item(DirectoryItem('/path/to/game/snake.py', 1, 'snake.py', {
    'type': 'file',
    'content': 'class Snake:\n    def __init__(self):\n        self.length = 1',
    'summary': None,
    'short_summary': None,
    'tags': []
}))

    # Convert to nested dictionary
    nested_dict = structure.to_nested_dict()

    # Print the result in a readable format
    print(json.dumps(nested_dict, indent=2))
```
The above code will generate the following output to the console:
```json
{
  "path": {
    "to": {
      "game": {
        "__keys__": {
          "type": "folder",
          "content": null,
          "summary": null,
          "short_summary": null,
          "tags": []
        },
        "game_loop.py": {
          "__keys__": {
            "type": "file",
            "content": "def main_loop():\n    while True:\n        update()\n        render()",
            "summary": null,
            "short_summary": null,
            "tags": []
          }
        },
        "snake.py": {
          "__keys__": {
            "type": "file",
            "content": "class Snake:\n    def __init__(self):\n        self.length = 1",
            "summary": null,
            "short_summary": null,
            "tags": []
          }
        }
      }
    }
  }
}
```

### Working with DirectoryItem Class
The most basic element of a directory structure is an item represented by the `DirectoryItem` class. This class is an abstracted object representing a `file` or `folder`. Each object holds valuable metadata about the underlying item, including summaries of the contents which can be generated with AI.
```python
    DirectoryItem(
        path='/path/to/project/README.md',
        level=1,
        name='README.md',
        metadata={
            'type': 'file',
            'size': '256B',
            'content': '# Project Documentation',
            'creation_date': '2024-01-01'
        }
    )
```

## Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.

## License
This project is licensed under the MIT License. See the LICENSE file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dirmapper-core",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "directory, mapping, summarization",
    "author": null,
    "author_email": "Nash Dean <nashdean.github@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/65/6a/95e077dbdd6182ff53ef0ed4c9b18e32486c9e00df218e97de5a28ef34b6/dirmapper_core-0.2.2.tar.gz",
    "platform": null,
    "description": "# dirmapper-core\nA directory mapping library that aids in visualization and directory structuring.\n# dirmapper-core\n\nA directory mapping library that aids in visualization and directory structuring.\n\n## Features\n\n- Generate directory structures in various styles (tree, list, flat, etc.)\n- Apply custom formatting to directory structures (plain text, JSON, HTML, Markdown, etc.)\n- Ignore specific files and directories using patterns\n- Summarize directory contents using AI (local or API-based)\n\n## Installation\n\nTo install the library, use pip:\n\n```sh\npip install dirmapper-core\n```\n\n## Usage\n### Generating Directory Structure\nYou can generate a directory structure using the `DirectoryStructureGenerator` class. Here is an example:\n```python\n# Example usage\n\nfrom dirmapper_core.generator.directory_structure_generator import DirectoryStructureGenerator\nfrom dirmapper_core.ignore.path_ignorer import PathIgnorer\nfrom dirmapper_core.styles.tree_style import TreeStyle\nfrom dirmapper_core.formatter.formatter import PlainTextFormatter\n\n# Define ignore patterns\nignore_patterns = [\n    SimpleIgnorePattern('.git/'),\n    SimpleIgnorePattern('.github/'),\n    SimpleIgnorePattern('__pycache__/')\n]\n\n# Initialize PathIgnorer\npath_ignorer = PathIgnorer(ignore_patterns)\n\n# Initialize DirectoryStructureGenerator\ngenerator = DirectoryStructureGenerator(\n    root_dir='./path/to/your/directory',\n    output='output.txt',\n    ignorer=path_ignorer,\n    sorting_strategy=AscendingSortStrategy(case_sensitive=False),\n    style=TreeStyle(),\n    formatter=PlainTextFormatter()\n)\n\n# Generate the directory structure into the style specified when initializing DirectoryStructureGenerator\nstructure = generator.generate() # Returns str\n```\nGenerating a directory structure results in a formatted string depending on your style and formatter. Here is an example of the `TreeStyle`:\n```\n/path/to/root/directory\n\u251c\u2500\u2500 requirements.txt\n\u251c\u2500\u2500 tests/\n\u2502   \u251c\u2500\u2500 test1.py\n\u2502   \u2514\u2500\u2500 __init__.py\n\u251c\u2500\u2500 docs/\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 setup.py\n\u251c\u2500\u2500 .gitignore\n\u251c\u2500\u2500 src/\n\u2502   \u2514\u2500\u2500 snake_game/\n\u2502       \u251c\u2500\u2500 __init__.py\n\u2502       \u251c\u2500\u2500 utils/\n\u2502       \u2502   \u2514\u2500\u2500 helper.py\n\u2502       \u2514\u2500\u2500 main.py\n```\nSee the [styles](dirmapper_core/styles) folder for all valid style examples.\n\nYou may also generate a raw DirectoryStructure object if you set the parameter `styled` to False in the `generate()` method. This allows access to the `DirectoryStructure` class helper functions and access to `DirectoryItems`\n```python\n# ...\nstructure = generator.generate(styled=False) # Returns DirectoryStructure object\n\n# Access file content lazily\nfor item in structure.to_list():\n    if item.metadata.get('content') is not None:\n        print(f\"Content of {item.path}: {item.content}\")\n```\n\n### Creating Directory Structure from Template\nYou can create a directory structure from a template using the `StructureWriter` class. Here is an example:\n```python\nfrom dirmapper_core.writer.structure_writer import StructureWriter\n\n# Define the base path where the structure will be created\nbase_path = 'Path/To/Your/Project'\n\n# Define the structure template\nstructure_template = {\n    \"meta\": {\n        \"version\": \"2.0\",\n        \"source\": \"dirmapper\",\n        \"author\": \"root\",\n        \"root_path\": base_path,\n        \"creation_date\": \"2024-11-01T20:06:14.510200\",\n        \"last_modified\": \"2024-11-01T20:06:14.510211\"\n    },\n    \"template\": {\n        \"requirements.txt\": {},\n        \"tests/\": {\n            \"test1.py\": {},\n            \"__init__.py\": {}\n        },\n        \"docs/\": {},\n        \"README.md\": {},\n        \"setup.py\": {},\n        \".gitignore\": {},\n        \"src/\": {\n            \"snake_game/\": {\n                \"__init__.py\": {},\n                \"utils/\": {\n                    \"helper.py\": {}\n                },\n                \"main.py\": {}\n            }\n        }\n    }\n}\n\n# Initialize StructureWriter\nwriter = StructureWriter(base_path)\n\n# Create the directory structure\nwriter.create_structure(structure_template)\n\n# Write the structure to OS file system\nwriter.write_structure()\n```\n\n### Writing Directory Structure to Template File\nYou can write the generated directory structure to a template file using the `write_template` function. Here is an example:\n```python\nfrom dirmapper_core.writer.template_writer import write_template\n\n# Define the path to the template file\ntemplate_path = 'path/to/your/template.json'\n\n# Define the structure template\nstructure_template = {\n    \"meta\": {\n        \"version\": \"1.1\",\n        \"source\": \"dirmapper\",\n        \"author\": \"root\",\n        \"root_path\": template_path,\n        \"creation_date\": \"2024-11-01T20:06:14.510200\",\n        \"last_modified\": \"2024-11-01T20:06:14.510211\"\n    },\n    \"template\": {\n        \"requirements.txt\": {},\n        \"tests/\": {\n            \"test1.py\": {},\n            \"__init__.py\": {}\n        },\n        \"docs/\": {},\n        \"README.md\": {},\n        \"setup.py\": {},\n        \".gitignore\": {},\n        \"src/\": {\n            \"snake_game/\": {\n                \"__init__.py\": {},\n                \"utils/\": {\n                    \"helper.py\": {}\n                },\n                \"main.py\": {}\n            }\n        }\n    }\n}\n\nwrite_template(template_path, structure_template)\n```\nYou may also use a valid styled directory string (i.e. `tree`) as your `structure_template` in the example above to write a YAML or JSON template file.\n\n### Writing a Directory Structure Formatted String to Template\nYou can create a JSON template from a formatted directory structure string. Here is a valid example using the `tree` style:\n```python\nimport json\nfrom dirmapper_core.writer.template_parser import TemplateParser\n\ntp = TemplateParser()\ntemplate = \"\"\"\n/path/to/root/directory\n\u251c\u2500\u2500 .git/\n\u251c\u2500\u2500 .github/\n\u2502   \u2514\u2500\u2500 workflows/\n\u2502       \u251c\u2500\u2500 check_version.yaml\n\u2502       \u251c\u2500\u2500 publish.yaml\n\u2502       \u2514\u2500\u2500 update-homebrew-formula.yml\n\u251c\u2500\u2500 .gitignore\n\u251c\u2500\u2500 .pytest_cache/\n\u251c\u2500\u2500 CHANGELOG.md\n\u251c\u2500\u2500 docs/\n\u251c\u2500\u2500 LICENSE\n\u251c\u2500\u2500 Makefile\n\u251c\u2500\u2500 pyproject.toml\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 requirements.txt\n\u251c\u2500\u2500 src/\n\u2502   \u2514\u2500\u2500 dirmapper/\n\u2502       \u251c\u2500\u2500 __init__.py\n\u2502       \u251c\u2500\u2500 ai/\n\u2502       \u2502   \u2514\u2500\u2500 summarizer.py\n\u2502       \u251c\u2500\u2500 api_client.py\n\u2502       \u251c\u2500\u2500 config.py\n\u2502       \u251c\u2500\u2500 config_manager.py\n\u2502       \u251c\u2500\u2500 data/\n\u2502       \u2502   \u2514\u2500\u2500 .mapping-ignore\n\u2502       \u251c\u2500\u2500 main.py\n\u2502       \u251c\u2500\u2500 reader/\n\u2502       \u2502   \u251c\u2500\u2500 __init__.py\n\u2502       \u2502   \u2514\u2500\u2500 reader.py\n\u2502       \u251c\u2500\u2500 token_manager.py\n\u2502       \u2514\u2500\u2500 writer/\n\u2502           \u251c\u2500\u2500 __init__.py\n\u2502           \u2514\u2500\u2500 writer.py\n\u2514\u2500\u2500 tests/\n    \u251c\u2500\u2500 __init__.py\n    \u2514\u2500\u2500 test_main.py\n\"\"\"\nparsed_template = tp.parse_from_directory_structure(template)\nprint(json.dumps(parsed_template, indent=4))\n```\nOther allowable styles include `list`, `flat`, and `indentation`.\n\n### Summarizing Directory Structure\nYou can summarize the directory structure using the `DirectorySummarizer` class. Here is an example:\n```python\n### Summarizing Directory Structure\nfrom dirmapper_core.generator.directory_structure_generator import DirectoryStructureGenerator\nfrom dirmapper_core.ai.summarizer import DirectorySummarizer\nfrom dirmapper_core.models.directory_structure import DirectoryStructure\nfrom dirmapper_core.models.directory_item import DirectoryItem\nfrom dirmapper_core.styles.tree_style import TreeStyle\n\n# Initialize DirectorySummarizer with configuration\nconfig = {\n    \"use_local\": False,\n    \"api_token\": \"your_openai_api_token\",\n    \"summarize_file_content\": True,  # Enable file content summarization\n    \"max_file_summary_words\": 50     # Limit file summaries to 50 words\n}\n\nsummarizer = DirectorySummarizer(config)\n\n# Create a DirectoryStructure instance\nroot_dir = \"path/to/root/project\"\ndsg = DirectoryStructureGenerator(\"path/to/root/project\")\nstructure = dsg.generate(styled = False)\n\n# Generate summaries\nresult = summarizer.summarize(structure)\nprint(json.dumps(result, indent=2))\n\n# Nicely format your short summaries to the terminal\nprint(TreeStyle.write_structure_with_short_summaries(structure))\n```\n\nIn the above example, you see that the __*result*__ from the `DirectorySummarizer` is a dict for easy JSON convertability. If you want to view the directory in a *tree* style, you can use the `write_structure_with_short_summaries` method which takes a DirectoryStructure object.\n\n### Summarizing Files\nYou can summarize individual files using the `FileSummarizer` class. Here is an example.\n```python\nfrom dirmapper_core.ai.summarizer import FileSummarizer\n\npreferences = {\n    \"use_local\": False,\n    \"api_token\": \"your_openai_api_token_here\"\n}\n\nfile_summarizer = FileSummarizer(preferences)\nfile_path = \"/path/to/your/file.py\"\nsummary = file_summarizer.summarize_file(file_path, max_words=150)\nprint(\"File Summary:\")\nprint(summary)\n```\n\n## Configuration\n### Ignoring Files and Directories\nYou can specify files and directories to ignore using the .mapping-ignore file or by providing patterns directly to the PathIgnorer class.\n\nExample `.mapping-ignore` file:\n```\n# Ignore .git directory\n.git/\n# Ignore all __pycache__ directories\nregex:^.*__pycache__$\n# Ignore all .pyc files\nregex:^.*\\.pyc$\n# Ignore all .egg-info directories\nregex:^.*\\.egg-info$\n# Ignore all dist directories\nregex:^.*dist$\n```\n\n### Custom Styles and Formatters\nYou can create custom styles and formatters by extending the BaseStyle and Formatter classes, respectively.\n\n## Appendix\n### Working with DirectoryStructure Class\nAll styles and many functions work with the DirectoryStructure class under the hood. This class is essentially an abstracted list of DirectoryItem objects. Below is a sample usage of initializing, adding items, and converting to a specialized dictionary object.\n```python\n# Create a new DirectoryStructure instance\nstructure = DirectoryStructure()\n\n# Add items to the structure\nstructure.add_item(DirectoryItem('/path/to/game', 0, 'game', {\n    'type': 'folder',\n    'content': None,\n    'summary': None,\n    'short_summary': None,\n    'tags': []\n}))\n\nstructure.add_item(DirectoryItem('/path/to/game/game_loop.py', 1, 'game_loop.py', {\n    'type': 'file',\n    'content': 'def main_loop():\\n    while True:\\n        update()\\n        render()',\n    'summary': None,\n    'short_summary': None,\n    'tags': []\n}))\n\nstructure.add_item(DirectoryItem('/path/to/game/snake.py', 1, 'snake.py', {\n    'type': 'file',\n    'content': 'class Snake:\\n    def __init__(self):\\n        self.length = 1',\n    'summary': None,\n    'short_summary': None,\n    'tags': []\n}))\n\n    # Convert to nested dictionary\n    nested_dict = structure.to_nested_dict()\n\n    # Print the result in a readable format\n    print(json.dumps(nested_dict, indent=2))\n```\nThe above code will generate the following output to the console:\n```json\n{\n  \"path\": {\n    \"to\": {\n      \"game\": {\n        \"__keys__\": {\n          \"type\": \"folder\",\n          \"content\": null,\n          \"summary\": null,\n          \"short_summary\": null,\n          \"tags\": []\n        },\n        \"game_loop.py\": {\n          \"__keys__\": {\n            \"type\": \"file\",\n            \"content\": \"def main_loop():\\n    while True:\\n        update()\\n        render()\",\n            \"summary\": null,\n            \"short_summary\": null,\n            \"tags\": []\n          }\n        },\n        \"snake.py\": {\n          \"__keys__\": {\n            \"type\": \"file\",\n            \"content\": \"class Snake:\\n    def __init__(self):\\n        self.length = 1\",\n            \"summary\": null,\n            \"short_summary\": null,\n            \"tags\": []\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n### Working with DirectoryItem Class\nThe most basic element of a directory structure is an item represented by the `DirectoryItem` class. This class is an abstracted object representing a `file` or `folder`. Each object holds valuable metadata about the underlying item, including summaries of the contents which can be generated with AI.\n```python\n    DirectoryItem(\n        path='/path/to/project/README.md',\n        level=1,\n        name='README.md',\n        metadata={\n            'type': 'file',\n            'size': '256B',\n            'content': '# Project Documentation',\n            'creation_date': '2024-01-01'\n        }\n    )\n```\n\n## Contributing\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\nThis project is licensed under the MIT License. See the LICENSE file for details.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 nashdean  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Core library for directory mapping and summarization",
    "version": "0.2.2",
    "project_urls": {
        "Changelog": "https://github.com/nashdean/dirmapper-core/blob/master/CHANGELOG.md",
        "Issues": "https://github.com/nashdean/dirmapper-core/issues",
        "Source": "https://github.com/nashdean/dirmapper-core"
    },
    "split_keywords": [
        "directory",
        " mapping",
        " summarization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2846cf922e686a691dfffe95f9be51b34bedfff761f6b7d0852941f34992127a",
                "md5": "9ab120a8570220b165287b7418064f96",
                "sha256": "a6e5a0fde3a1fa334d1f54f7eb0ed8e7646ab18b1366b07e41141b0b75898748"
            },
            "downloads": -1,
            "filename": "dirmapper_core-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ab120a8570220b165287b7418064f96",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 47309,
            "upload_time": "2024-12-21T02:26:36",
            "upload_time_iso_8601": "2024-12-21T02:26:36.227211Z",
            "url": "https://files.pythonhosted.org/packages/28/46/cf922e686a691dfffe95f9be51b34bedfff761f6b7d0852941f34992127a/dirmapper_core-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "656a95e077dbdd6182ff53ef0ed4c9b18e32486c9e00df218e97de5a28ef34b6",
                "md5": "1a3cddf4abbde9c7043de4cd35419d87",
                "sha256": "447b560c983cba06aabddca7bdae88a582385d234608ce4e5b7e1db356e5f8bb"
            },
            "downloads": -1,
            "filename": "dirmapper_core-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1a3cddf4abbde9c7043de4cd35419d87",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 43745,
            "upload_time": "2024-12-21T02:26:38",
            "upload_time_iso_8601": "2024-12-21T02:26:38.567487Z",
            "url": "https://files.pythonhosted.org/packages/65/6a/95e077dbdd6182ff53ef0ed4c9b18e32486c9e00df218e97de5a28ef34b6/dirmapper_core-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 02:26:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nashdean",
    "github_project": "dirmapper-core",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "openai",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": []
        }
    ],
    "lcname": "dirmapper-core"
}
        
Elapsed time: 0.43013s