{"id":34096065,"url":"https://github.com/markuskimius/getopt-py","last_synced_at":"2026-03-12T15:03:33.194Z","repository":{"id":45746217,"uuid":"170439662","full_name":"markuskimius/getopt-py","owner":"markuskimius","description":"getopt library for Python","archived":false,"fork":false,"pushed_at":"2022-07-15T17:49:19.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-16T19:26:55.652Z","etag":null,"topics":["getopt"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markuskimius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-13T04:23:01.000Z","updated_at":"2024-11-08T00:56:54.000Z","dependencies_parsed_at":"2022-08-25T14:40:11.801Z","dependency_job_id":null,"html_url":"https://github.com/markuskimius/getopt-py","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/markuskimius/getopt-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markuskimius%2Fgetopt-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markuskimius%2Fgetopt-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markuskimius%2Fgetopt-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markuskimius%2Fgetopt-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markuskimius","download_url":"https://codeload.github.com/markuskimius/getopt-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markuskimius%2Fgetopt-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30429309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["getopt"],"created_at":"2025-12-14T15:26:56.944Z","updated_at":"2026-03-12T15:03:33.185Z","avatar_url":"https://github.com/markuskimius.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getopt-py\n\nA classic getopt library for Python with long options and optional arguments\nsupport.\n\n\n## Motivation\n\nFor developers that find [argparse] too constraining.\n\n\n## Example\n\n```python\nimport getopts\n\n...\n\ngetopt = getopts.getopts(sys.argv, {\n    \"h\": 0         , \"help\"   : 0,\n    \"o\": 1         , \"output\" : 1,\n    \"p\": is_port   , \"port\"   : is_port,\n    \"v\": [is_int,1], \"verbose\": [is_int,1]\n})\n\nfor c in getopt:\n    if   c in (\"-\")           : opts.files.append(getopt.optarg)\n    elif c in (\"h\", \"help\")   : usage() ; sys.exit(0)\n    elif c in (\"o\", \"output\") : opts.output  = getopt.optarg\n    elif c in (\"p\", \"port\")   : opts.port    = int(getopt.optarg)\n    elif c in (\"v\", \"verbose\"): opts.verbose = int(getopt.optarg)\n    else: sys.exit(1)\n```\n\n- `-h` and `--help` take no arguments (0).\n- `-o` and `--output` take any argument (1).\n- `-p` and `--port` take an argument that, when passed to the `is_port`\n  function, returns True.\n- `-v` and `--verbose` take an optional argument that, when passed to the\n  `is_int` function, returns True.  If no argument is specified, it defaults to\n  `1`.\n\nSee [example.py] for a more complete example.\n\n\n## Features\n\nThe features are based on GNU `getopt_long`:\n\n- Short options.  Options may be combined (`-a -b -c` is equivalent to `-abc`).\n  If the option takes a mandatory argument, the argument may appear with or\n  without whitespaces (`-o value` is equivalent to `-ovalue`).\n\n- Long options.  If the option takes a mandatory argument, the argument may\n  appear with or without an equal sign (`--option value` is equivalent to\n  `--option=value`).\n\n- Optional arguments. If the option takes an optional argument, the argument\n  must appear without a space after a short option (`-ovalue`) or with an equal\n  sign after a long option (`--option=value`).\n\n- Options may appear in any order.\n\n- `--` can be used to denote the end of options.\n\n\n## Installation\n\nWith pip:\n\n```\npip install getopts\n```\n(note the plural 's')\n\nWith [dpm]:\n```\ndpm install https://github.com/markuskimius/getopt-py.git\n```\n\n\n## Usage\n\n```python\ngetopts.getopts(argv, optdict)\n```\n\nAll parameters are mandatory:\n- `argv` - The argument list (e.g., sys.argv)\n- `optdict` - A dictionary containing the valid options and a specification\n  of whether they take an argument. The keys are the options. The value may be\n  `0` if the option takes no argument, or `1` if it takes an argument. Instead\n  of `0` or `1`, it may specify a validation function that returns `1` if the\n  argument is valid, or `0` otherwise. To specify the argument as optional,\n  surround it in brackets (make it a list), with the optional second element\n  specifying the default value.\n\nThe function returns an iterable object that, if evaluated, returns one of the\nfollowing:\n- `-`: An optionless argument.  The value of the argument is stored in `getopt.optarg`.\n- `?`: An invalid option. An error message has been printed to `getopt.stderr` and the\n  option that caused the error is stored in `getopt.optopt`.\n- All other values: A valid option.  This value is also stored in `getopt.optopt`.  If\n  the option takes an argument, the value is stored in `getopt.optarg`.\n\nThe following variable names are available:\n- `getopt.optind`: The index of the next `argv`.\n- `getopt.optopt`: The last option processed.\n- `getopt.optarg`: The argument to the last option.\n\n\n## License\n\n[Apache 2.0]\n\n\n[C-style getopt parser]: \u003chttps://docs.python.org/3.1/library/getopt.html\u003e\n[argparse]: \u003chttps://docs.python.org/3/library/argparse.html\u003e\n[getopt-tcl]: \u003chttps://github.com/markuskimius/getopt-tcl/\u003e\n[example.py]: \u003chttps://github.com/markuskimius/getopt-py/blob/master/test/example.py\u003e\n[Apache 2.0]: \u003chttps://github.com/markuskimius/getopt-py/blob/master/LICENSE\u003e\n[dpm]: \u003chttps://github.com/markuskimius/dpm\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkuskimius%2Fgetopt-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkuskimius%2Fgetopt-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkuskimius%2Fgetopt-py/lists"}