Skip to main content

A simple Python module for managing dependencies at runtime

Project description

runtime_dependency_manager

runtime_dependency_manager is a simple Python module for managing dependencies at runtime. It is designed for small scripts that do not use a requirements.txt file. This module allows you to define and install dependencies directly within your script, making it ideal for quick scripts and prototypes.

Installation

You can install runtime_dependency_manager using pip:

pip install runtime_dependency_manager

Usage

Here's an example of how to use runtime_dependency_manager in your script:

from runtime_dependency_manager import RuntimeDependencyManager

with RuntimeDependencyManager(install_if_missing=True) as mgr:
    mgr.index_url = "https://pypi.org/simple"

    with mgr.package('IPy', '>=1.1') as pkg:
        pkg.from_module('IPy').import_modules('IP', 'IPSet')

    with mgr.package('pymongo', '>=3.11.4, <4.0.0') as pkg:
        pkg.import_module('pymongo')
        pkg.from_module('bson').import_module('ObjectId')

    with mgr.package('paramiko', '==2.7.2') as pkg:
        pkg.from_module('paramiko').import_modules('SSHClient', 'AutoAddPolicy', 'SSHConfig', 'SSHException')

    with mgr.package('pyyaml', '>=5.4.1, <6.0.0', optional=True) as pkg:
        pkg.import_module('yaml')

API

RuntimeDependencyManager

RuntimeDependencyManager(install_if_missing=False, index_url=None, extra_index_urls=None, trusted_hosts=None)

  • install_if_missing: Whether to install missing packages automatically.
  • index_url: The base URL of the Python Package Index.
  • extra_index_urls: Additional URLs of package indexes.
  • trusted_hosts: List of trusted hosts.

Methods

  • package(name, version_spec=None, optional=False): Adds a package to the dependency list.

Package

Methods

  • import_module(module_name): Adds an import statement for the specified module.
  • import_modules(*modules): Adds import statements for multiple modules.
  • from_module(from_name): Creates an ImportFrom object for importing specific items from a module.
  • as_module(alias): Specifies an alias for the imported module.

ImportFrom

Methods

  • import_module(module_name): Adds an import statement for importing a specific item from a module.
  • import_modules(*modules): Adds import statements for importing multiple items from a module.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

If you would like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

  1. Fork the project.
  2. Create a feature branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.

Acknowledgments

  • The Python community for the packaging module.
  • Anyone who has contributed to this project.

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

runtime_dependency_manager-0.1.4.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

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

runtime_dependency_manager-0.1.4-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file runtime_dependency_manager-0.1.4.tar.gz.

File metadata

File hashes

Hashes for runtime_dependency_manager-0.1.4.tar.gz
Algorithm Hash digest
SHA256 da4513e9706861607686c5bb0b13c22f7832952e3eceff16163d682e7fba0f6e
MD5 a62a76a93def6bf80464d2539c3a64db
BLAKE2b-256 cfaa51cf7498b731a5c416ca35725b64b0c7f6a3fdcea12c59803820e2ab9eb1

See more details on using hashes here.

File details

Details for the file runtime_dependency_manager-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for runtime_dependency_manager-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8a088bfd2b5c15ccae6744468a67f9c205511c29e098a88f3cc2d7acc30d520d
MD5 82bd67b38db193ed129b7c36f3dd01af
BLAKE2b-256 0a293449cde9aea7d1287fbccf26744a9972b7f66486f3b37c00f1bbae6b2750

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