lilliepy-import


Namelilliepy-import JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/websitedeb/lilliepy-import
Summarydynamic importer for LilliePy framework
upload_time2024-12-30 03:20:40
maintainerNone
docs_urlNone
authorSarthak Ghoshal
requires_python>=3.6
licenseMIT
keywords lilliepy lilliepy-importer reactpy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # lilliepy_import

lilliepy_import is a Python package that provides utility functions for dynamically importing modules and components. 
It is designed to make it easy to set a component directory and load specific functions or classes dynamically.

## Features

- Dynamically set a component folder using `Importer`.
- Import specific functions or classes from files in the component folder with `_import`.
- Supports dynamic module imports with error handling.

## Installation

To install the package, use pip:

```bash
pip install lilliepy_import
```

## Usage

### Setting the Component Folder

First, set the component folder where your modules are stored:

```python
from lilliepy_import import Importer

# Set the component folder
Importer("components")
```

### Importing a Function or Class

You can then dynamically import a specific function or class:

```python
from lilliepy_import import _import

# Dynamically import a function or class
try:
    my_function = _import("my_module.py", "my_function")
    if my_function:
        my_function()  # Call the imported function
    else:
        print("Function not found in the module.")
except Exception as e:
    print(f"Error: {e}")
```

### Example

Assume the following directory structure:

```
project/
├── components/
│   └── my_module.py
└── main.py
```

**my_module.py**:
```python
from reactpy import component, html

@component
def my_function():
    return html.h1("yo")
```

**main.py**:
```python
from lilliepy_import import Importer, _import

# Set the component folder
Importer("components")

# Import and call the function
func = _import("my_module.py", "my_function")
if func:
    func()
```

When you run `main.py`, the output will be:

```
Hello from my_function!
```

## Error Handling

- Raises a `ValueError` if the component folder is not set before calling `_import`.
- Raises a `FileNotFoundError` if the specified file does not exist.
- Handles cases where the function or class is not found in the module.

## License

This project is licensed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/websitedeb/lilliepy-import",
    "name": "lilliepy-import",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "lilliepy, lilliepy-importer, reactpy",
    "author": "Sarthak Ghoshal",
    "author_email": "sarthak22.ghoshal@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0b/c4/95de4805ef6b818bb41251b921faa8361494935df596accf80d03bc49ae7/lilliepy_import-0.1.tar.gz",
    "platform": null,
    "description": "# lilliepy_import\r\n\r\nlilliepy_import is a Python package that provides utility functions for dynamically importing modules and components. \r\nIt is designed to make it easy to set a component directory and load specific functions or classes dynamically.\r\n\r\n## Features\r\n\r\n- Dynamically set a component folder using `Importer`.\r\n- Import specific functions or classes from files in the component folder with `_import`.\r\n- Supports dynamic module imports with error handling.\r\n\r\n## Installation\r\n\r\nTo install the package, use pip:\r\n\r\n```bash\r\npip install lilliepy_import\r\n```\r\n\r\n## Usage\r\n\r\n### Setting the Component Folder\r\n\r\nFirst, set the component folder where your modules are stored:\r\n\r\n```python\r\nfrom lilliepy_import import Importer\r\n\r\n# Set the component folder\r\nImporter(\"components\")\r\n```\r\n\r\n### Importing a Function or Class\r\n\r\nYou can then dynamically import a specific function or class:\r\n\r\n```python\r\nfrom lilliepy_import import _import\r\n\r\n# Dynamically import a function or class\r\ntry:\r\n    my_function = _import(\"my_module.py\", \"my_function\")\r\n    if my_function:\r\n        my_function()  # Call the imported function\r\n    else:\r\n        print(\"Function not found in the module.\")\r\nexcept Exception as e:\r\n    print(f\"Error: {e}\")\r\n```\r\n\r\n### Example\r\n\r\nAssume the following directory structure:\r\n\r\n```\r\nproject/\r\n\u00e2\u201d\u0153\u00e2\u201d\u20ac\u00e2\u201d\u20ac components/\r\n\u00e2\u201d\u201a   \u00e2\u201d\u201d\u00e2\u201d\u20ac\u00e2\u201d\u20ac my_module.py\r\n\u00e2\u201d\u201d\u00e2\u201d\u20ac\u00e2\u201d\u20ac main.py\r\n```\r\n\r\n**my_module.py**:\r\n```python\r\nfrom reactpy import component, html\r\n\r\n@component\r\ndef my_function():\r\n    return html.h1(\"yo\")\r\n```\r\n\r\n**main.py**:\r\n```python\r\nfrom lilliepy_import import Importer, _import\r\n\r\n# Set the component folder\r\nImporter(\"components\")\r\n\r\n# Import and call the function\r\nfunc = _import(\"my_module.py\", \"my_function\")\r\nif func:\r\n    func()\r\n```\r\n\r\nWhen you run `main.py`, the output will be:\r\n\r\n```\r\nHello from my_function!\r\n```\r\n\r\n## Error Handling\r\n\r\n- Raises a `ValueError` if the component folder is not set before calling `_import`.\r\n- Raises a `FileNotFoundError` if the specified file does not exist.\r\n- Handles cases where the function or class is not found in the module.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "dynamic importer for LilliePy framework",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/websitedeb/lilliepy-import"
    },
    "split_keywords": [
        "lilliepy",
        " lilliepy-importer",
        " reactpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c3147b0db11d4700a46132c2d7e1e27034d5b94e07d5da5fb64b2a1286dc5179",
                "md5": "17eff602a0fadac558446adbbb21efea",
                "sha256": "3eb3bb96b4974a001fa3489cd1bcd3fd140a1bbd07cf9147c9ef8107d07e15e2"
            },
            "downloads": -1,
            "filename": "lilliepy_import-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "17eff602a0fadac558446adbbb21efea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 2941,
            "upload_time": "2024-12-30T03:20:39",
            "upload_time_iso_8601": "2024-12-30T03:20:39.849320Z",
            "url": "https://files.pythonhosted.org/packages/c3/14/7b0db11d4700a46132c2d7e1e27034d5b94e07d5da5fb64b2a1286dc5179/lilliepy_import-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0bc495de4805ef6b818bb41251b921faa8361494935df596accf80d03bc49ae7",
                "md5": "8b0e2882c31135626e25db31c63aced2",
                "sha256": "f159b2eb464e6464723cd5f0e90f3323169d9fc6485fb89881077a0b1476ac17"
            },
            "downloads": -1,
            "filename": "lilliepy_import-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8b0e2882c31135626e25db31c63aced2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 2886,
            "upload_time": "2024-12-30T03:20:40",
            "upload_time_iso_8601": "2024-12-30T03:20:40.979297Z",
            "url": "https://files.pythonhosted.org/packages/0b/c4/95de4805ef6b818bb41251b921faa8361494935df596accf80d03bc49ae7/lilliepy_import-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-30 03:20:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "websitedeb",
    "github_project": "lilliepy-import",
    "github_not_found": true,
    "lcname": "lilliepy-import"
}
        
Elapsed time: 0.45087s