Skip to main content

A lightweight object oriented lib for Python 3.8+ to help create CLI programs more easily. It has an elegant design taking advantage of built-in modules, and delivering a conducive environment to fast development and readability.

Project description


Argila Parser
version 2.0.0


What is it?

It's a lightweight object oriented lib for Python 3.8+ to help create CLI programs more easily. It has an elegant design taking advantage of built-in modules, and delivering a conducive environment to fast development and readability.


Quickstart

This is the basic structure of your program, the class App represents the application, and the methods within it are the commands.

The typing module provides a built-in range of type hints, giving the developer a sophisticated way of accepting complex arguments. Any, Union, Tuple, List are currently supported.

import typing
from argila import Argila

@Argila.create
class App:
    @Argila.command(
        {
            'name': 'add',
            'positional': {
                'a': 'First element of the equation',
                'b': 'Second element of the equation'
            }
        }
    )
    def add(self, a: typing.Union[int, float], b: typing.Union[int, float]) -> None:
        '''This command adds two numbers together'''
        print(a + b)


if __name__ == '__main__':
    Argila.run()

A method is only considered a command if it has the @Argila.command decorator.
Below is the configuration dict in its completeness.

{
    'name': 'command',
    'positional': {
        'a': 'Obligatory argument'
    },
    'optional': {
        'b': 'Optional argument'
    },
    'keyword': {
        'c': 'Keyword argument'
    }
}

* means the key is obligatory.

name*: The name of the command used to call it. (This is the only nomination that matters, the method can have any name you'd like)

positional: A dict with all the positional arguments, the key should have the same name as the actual parameter in the method; the value is a short description of it. You invoke this argument with --key value.

optional: Same as positional, but optional arguments are not obligatory. You invoke this argument with --key value.

keyword: Same as positional, but keyword arguments are not obligatory and work as flags (bools). You invoke this argument with --key.

The order in which you invoke each argument does not matter, as long as you keep the syntax --key value. The examples add --a 1 --b 2 and add --b 2 --a 1 are both correct.


Apart from it, the docstring '''This command adds two numbers together''' is how you set the description of a command. If not set, the description defaults to an empty string.


Lastly, call Argila.run(), which is the method that will trigger all the subsequent others.

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

argilaparser-2.0.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

argilaparser-2.0.1-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

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