Skip to main content

A utility for seamless argument parsing in IPython notebooks and Python scripts.

Project description

Python Argument Parser for Notebooks and Scripts

Introduction

This Python module provides a versatile argument parsing solution that works seamlessly both in Jupyter notebooks (or similar environments) and standard Python scripts. It allows the same code to accept arguments in two different contexts, making it easier to write code that is flexible and easy to test.

The document is helped by ChatGPT 4.0

Features

  • Dual Compatibility : Works with Jupyter notebooks and standard Python scripts.
  • Easy Integration : Simple to integrate into existing Python projects.
  • Dynamic Argument Parsing : Automatically switches between easydict and argparse depending on the execution environment.

Requirements

  • easydict
  • argparse

Installation

Ensure that you have easydict installed. You can install it using pip:

pip install easydict

Usage

Defining Arguments

First, define your arguments in a dictionary format. For example:

args_dict = { "arg1": value1, "arg2": value2, // Add more arguments as needed }

Parsing Arguments

Then, simply call the ipython_args function with your arguments dictionary:

args = ipython_args(args_dict)

In a Jupyter notebook environment, args will be an EasyDict object, allowing you to access arguments using dot notation (args.arg1). In a standard script, args will be the usual argparse.Namespace object.

Checking Environment

The is_notebook function can be used independently to check if the code is running in a Jupyter notebook environment.

Example

Here's a simple example demonstrating how to use this module:

from ipython_args import ipython_args # Define your arguments here args_dict = { "epoch": 10, "learning_rate": 0.001 } # Parse arguments args = ipython_args(args_dict) # Accessing arguments print(args.epoch) print(args.learning_rate)

You can use is_notebook function to check the environment is notebook or not

from ipython_args import is_notebook # Check whether the current environment is notebook shell or not current_env_notebook = is_notebook())

Contributing & Acknowledgements

Thanks for professor Dr. Lee, Soo-Hong who encourage me to upload the project.

This projects are side-project of the National Research Foundation of Korea, ‘Development of a 2-axis ankle exoskeleton robot to identify intentions using deep learning-based EMG images’ (No.2021R1I1A205215811)

License

This project is open-source and available under the MIT License.

Copyright (c) 2018 The Python Packaging Authority

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.

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

ipython_args-1.0.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

ipython_args-1.0.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file ipython_args-1.0.3.tar.gz.

File metadata

  • Download URL: ipython_args-1.0.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for ipython_args-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1ba90f503daf01e2cf771b1a11083becc7b4589e62fc25314d9f7ac196f12c82
MD5 e940d9ab747bc76dee87ccd43b325d94
BLAKE2b-256 5fe6feebd8f4ef84c6bb823d52378ae20328bb8f5f6e50aa70909786ec74e6f7

See more details on using hashes here.

File details

Details for the file ipython_args-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ipython_args-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9177eb67edfcf26daf48e904106ca4bedc33fdf1d3b565d85fc7d7243f2f900e
MD5 b6c34b6a4793d1721522ca9740ba0133
BLAKE2b-256 54e3958ab5fa181d13b43552d9a3ee947115576d89f80b6fe487d6bbd9927413

See more details on using hashes here.

Supported by

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