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.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

ipython_args-1.0.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ipython_args-1.0.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for ipython_args-1.0.2.tar.gz
Algorithm Hash digest
SHA256 76c9131daff2be07b987d8937852fa4715299a54d3cfed44684d9acc25dcbbf9
MD5 688ce569b05c21eb52d70a4cf365a3d2
BLAKE2b-256 9383a79c159f2f7c9b6ba0cdf11ee20d2d084441771c424cb1bbf2b224c12efa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ipython_args-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8781e6276168fdaa976582b895fdda70564ec763a06e6d04034f5c885ddd8e6d
MD5 0d201f9e8aa9aa12f93ce181132d8c9e
BLAKE2b-256 2b1572708adece8e5b31a704fd02371ec2b174c34be5d1555b27d5936b7e0d89

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