Skip to main content

dynamic importer for LilliePy framework

Project description

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:

pip install lilliepy_import

Usage

Setting the Component Folder

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

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:

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:

from reactpy import component, html

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

main.py:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lilliepy_import-1.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lilliepy_import-1.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file lilliepy_import-1.3.tar.gz.

File metadata

  • Download URL: lilliepy_import-1.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for lilliepy_import-1.3.tar.gz
Algorithm Hash digest
SHA256 e5bf7559f5f92667e5ceae486adc1572d94711219f48f1b237a9f8ea0e1645ca
MD5 b629c7c302b9fa3ac9c0996e6bcf4125
BLAKE2b-256 114c5463494b6cfc18e8d676988b3afb25c97137b72a1e2f612853cce1b1bb82

See more details on using hashes here.

File details

Details for the file lilliepy_import-1.3-py3-none-any.whl.

File metadata

  • Download URL: lilliepy_import-1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for lilliepy_import-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82ad0aae16c0e228191d2b9e6c870a196a1c23a18c3a6272948245c033f81c6f
MD5 36ba540a18acb01027f0e7ec3d899f5f
BLAKE2b-256 4c344a9bd0cbc1bd43f5706ad5777e2283da9dae254a7b7a1fbf2f55a7e513ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page