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

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

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

Uploaded Source

Built Distribution

ipython_args-1.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ipython_args-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 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.1.tar.gz
Algorithm Hash digest
SHA256 bf624f79bf0e05cb8f01a0d488154b35447b30efade648bb79ef9fed372b8ee0
MD5 f5f5d4f33dd2c6b5d485bb00c921ae9f
BLAKE2b-256 07fbae4558735bbcd42153fa323ca993c349590b523d587af2af0f847528668f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ipython_args-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 531a784652e457d4234d465bfd6c53ac6e7df7787922fc5792ed67b96096f617
MD5 674573b995fc9b93016e6a31a9bb7a23
BLAKE2b-256 3f85aaad9b8c6845a36261378ecb2f317bb1841722ddcdc2ea005caeb5b19d8b

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