pax_global_header 0000666 0000000 0000000 00000000064 13520106167 0014513 g ustar 00root root 0000000 0000000 52 comment=c1a7e2f21fb95e37d80d3e32c7ecbefa12140edf
python-fire-0.2.1/ 0000775 0000000 0000000 00000000000 13520106167 0013757 5 ustar 00root root 0000000 0000000 python-fire-0.2.1/.gitignore 0000664 0000000 0000000 00000002224 13520106167 0015747 0 ustar 00root root 0000000 0000000 # Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# PyCharm IDE
.idea/
# Type-checking
.pytype/
python-fire-0.2.1/.travis.yml 0000664 0000000 0000000 00000001712 13520106167 0016071 0 ustar 00root root 0000000 0000000 language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
# Workaround for testing Python 3.7:
# https://github.com/travis-ci/travis-ci/issues/9815
matrix:
include:
- python: 3.7
dist: xenial
sudo: yes
before_install:
- pip install --upgrade setuptools pip
- pip install --upgrade pylint pytest pytest-pylint pytest-runner
install:
- pip install termcolor
- pip install hypothesis python-Levenshtein
- python setup.py develop
script:
- python -m pytest # Run the tests without IPython.
- pip install ipython
- python -m pytest # Now run the tests with IPython.
- pylint fire --ignore=test_components_py3.py,parser_fuzz_test.py,console
- pip install pytype
# Run type-checking, excluding files that define or use py3 features in py2.
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then
pytype -x
fire/fire_test.py
fire/inspectutils_test.py
fire/test_components_py3.py;
else
pytype; fi
python-fire-0.2.1/CONTRIBUTING.md 0000664 0000000 0000000 00000001730 13520106167 0016211 0 ustar 00root root 0000000 0000000 # How to contribute
We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.
## Contributor License Agreement
Contributions to this project must be accompanied by a Contributor License
Agreement. You (or your employer) retain the copyright to your contribution,
this simply gives us permission to use and redistribute your contributions as
part of the project. Head over to to see
your current agreements on file or to sign a new one.
You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.
## Code reviews
All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult [GitHub Help] for more
information on using pull requests.
[GitHub Help]: https://help.github.com/articles/about-pull-requests/
python-fire-0.2.1/LICENSE 0000664 0000000 0000000 00000001075 13520106167 0014767 0 ustar 00root root 0000000 0000000 Copyright 2017 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
python-fire-0.2.1/MANIFEST.in 0000664 0000000 0000000 00000000020 13520106167 0015505 0 ustar 00root root 0000000 0000000 include LICENSE
python-fire-0.2.1/README.md 0000664 0000000 0000000 00000007643 13520106167 0015250 0 ustar 00root root 0000000 0000000 # Python Fire [](https://github.com/google/python-fire)
_Python Fire is a library for automatically generating command line interfaces
(CLIs) from absolutely any Python object._
- Python Fire is a simple way to create a CLI in Python. [[1]](docs/benefits.md#simple-cli)
- Python Fire is a helpful tool for developing and debugging Python code. [[2]](docs/benefits.md#debugging)
- Python Fire helps with exploring existing code or turning other people's code
into a CLI. [[3]](docs/benefits.md#exploring)
- Python Fire makes transitioning between Bash and Python easier. [[4]](docs/benefits.md#bash)
- Python Fire makes using a Python REPL easier by setting up the REPL with the
modules and variables you'll need already imported and created. [[5]](docs/benefits.md#repl)
## Installation
To install Python Fire with pip, run: `pip install fire`
To install Python Fire with conda, run: `conda install fire -c conda-forge`
To install Python Fire from source, first clone the repository and then run:
`python setup.py install`
## Basic Usage
You can call `Fire` on any Python object:
functions, classes, modules, objects, dictionaries, lists, tuples, etc.
They all work!
Here's an example of calling Fire on a function.
```python
import fire
def hello(name="World"):
return "Hello %s!" % name
if __name__ == '__main__':
fire.Fire(hello)
```
Then, from the command line, you can run:
```bash
python hello.py # Hello World!
python hello.py --name=David # Hello David!
python hello.py --help # Shows usage information.
```
Here's an example of calling Fire on a class.
```python
import fire
class Calculator(object):
"""A simple calculator class."""
def double(self, number):
return 2 * number
if __name__ == '__main__':
fire.Fire(Calculator)
```
Then, from the command line, you can run:
```bash
python calculator.py double 10 # 20
python calculator.py double --number=15 # 30
```
To learn how Fire behaves on functions, objects, dicts, lists, etc, and to learn
about Fire's other features, see the [Using a Fire CLI page](docs/using-cli.md).
For additional examples, see [The Python Fire Guide](docs/guide.md).
## Why is it called Fire?
When you call `Fire`, it fires off (executes) your command.
## Where can I learn more?
Please see [The Python Fire Guide](docs/guide.md).
## Reference
| Setup | Command | Notes
| :------ | :------------------ | :---------
| install | `pip install fire` |
| Creating a CLI | Command | Notes
| :--------------| :--------------------- | :---------
| import | `import fire` |
| Call | `fire.Fire()` | Turns the current module into a Fire CLI.
| Call | `fire.Fire(component)` | Turns `component` into a Fire CLI.
Using a CLI | Command | Notes
:---------------------------------------------- | :-------------------------------------- | :----
[Help](docs/using-cli.md#help-flag) | `command --help` or `command -- --help` |
[REPL](docs/using-cli.md#interactive-flag) | `command -- --interactive` | Enters interactive mode.
[Separator](docs/using-cli.md#separator-flag) | `command -- --separator=X` | Sets the separator to `X`. The default separator is `-`.
[Completion](docs/using-cli.md#completion-flag) | `command -- --completion [shell]` | Generates a completion script for the CLI.
[Trace](docs/using-cli.md#trace-flag) | `command -- --trace` | Gets a Fire trace for the command.
[Verbose](docs/using-cli.md#verbose-flag) | `command -- --verbose` |
_Note that these flags are separated from the Fire command by an isolated `--`._
## License
Licensed under the
[Apache 2.0](https://github.com/google/python-fire/blob/master/LICENSE) License.
## Disclaimer
This is not an official Google product.
python-fire-0.2.1/docs/ 0000775 0000000 0000000 00000000000 13520106167 0014707 5 ustar 00root root 0000000 0000000 python-fire-0.2.1/docs/api.md 0000664 0000000 0000000 00000002263 13520106167 0016005 0 ustar 00root root 0000000 0000000 | Setup | Command | Notes
| :------ | :------------------ | :---------
| install | `pip install fire` |
| Creating a CLI | Command | Notes
| :--------------| :--------------------- | :---------
| import | `import fire` |
| Call | `fire.Fire()` | Turns the current module into a Fire CLI.
| Call | `fire.Fire(component)` | Turns `component` into a Fire CLI.
| Using a CLI | Command | Notes
| :------------- | :------------------------- | :---------
| [Help](using-cli.md#help-flag) | `command -- --help` |
| [REPL](using-cli.md#interactive-flag) | `command -- --interactive` | Enters interactive mode.
| [Separator](using-cli.md#separator-flag) | `command -- --separator=X` | This sets the separator to `X`. The default separator is `-`.
| [Completion](using-cli.md#completion-flag) | `command -- --completion [shell]` | Generate a completion script for the CLI.
| [Trace](using-cli.md#trace-flag) | `command -- --trace` | Gets a Fire trace for the command.
| [Verbose](using-cli.md#verbose-flag) | `command -- --verbose` |
_Note that flags are separated from the Fire command by an isolated `--` arg._
python-fire-0.2.1/docs/benefits.md 0000664 0000000 0000000 00000005214 13520106167 0017032 0 ustar 00root root 0000000 0000000 # Benefits of Python Fire
## Create CLIs in Python
It's dead simple. Simply write the functionality you want exposed at the command
line as a function / module / class, and then call Fire. With this addition of a
single-line call to Fire, your CLI is ready to go.
## Develop and debug Python code
When you're writing a Python library, you probably want to try it out as you go.
You could write a main method to check the functionality you're interested in,
but then you have to change the main method with every new experiment you're
interested in testing, and constantly updating the main method is a hassle.
You could also open an IPython REPL and import your library there and test it,
but then you have to deal with reloading your imports every time you change
something.
If you simply call Fire in your library, then you can run all of it's
functionality from the command line without having to keep making changes to
a main method. And if you use the `--interactive` flag to enter an IPython REPL
then you don't need to load the imports or create your variables; they'll
already be ready for use as soon as you start the REPL.
## Explore existing code; turn other people's code into a CLI
You can take an existing module, maybe even one that you don't have access to
the source code for, and call `Fire` on it. This lets you easily see what
functionality this code exposes, without you having to read through all the
code.
This technique can be a very simple way to create very powerful CLIs. Call
`Fire` on the difflib library and you get a powerful diffing tool. Call `Fire`
on the Python Imaging Library (PIL) module and you get a powerful image
manipulation command line tool, very similar in nature to ImageMagick.
The auto-generated help strings that Fire provides when you run a Fire CLI
allow you to see all the functionality these modules provide in a concise
manner.
## Transition between Bash and Python
Using Fire lets you call Python directly from Bash. So you can mix your Python
functions with the unix tools you know and love, like `grep`, `xargs`, `wc`,
etc.
Additionally since writing CLIs in Python requires only a single call to Fire,
it is now easy to write even one-off scripts that would previously have been in
Bash, in Python.
## Explore code in a Python REPL
When you use the `--interactive` flag to enter an IPython REPL, it starts with
variables and modules already defined for you. You don't need to waste time
importing the modules you care about or defining the variables you're going to
use, since Fire has already done so for you.
python-fire-0.2.1/docs/guide.md 0000664 0000000 0000000 00000042563 13520106167 0016340 0 ustar 00root root 0000000 0000000 ## The Python Fire Guide
### Introduction
Welcome to the Python Fire guide! Python Fire is a Python library that will turn
any Python component into a command line interface with just a single call to
`Fire`.
Let's get started!
### Installation
To install Python Fire from pypi, run:
`pip install fire`
Alternatively, to install Python Fire from source, clone the source and run:
`python setup.py install`
### Hello World
##### Version 1: `fire.Fire()`
The easiest way to use Fire is to take any Python program, and then simply call
`fire.Fire()` at the end of the program. This will expose the full contents of
the program to the command line.
```python
import fire
def hello(name):
return 'Hello {name}!'.format(name=name)
if __name__ == '__main__':
fire.Fire()
```
Here's how we can run our program from the command line:
```bash
$ python example.py hello World
Hello World!
```
##### Version 2: `fire.Fire()`
Let's modify our program slightly to only expose the `hello` function to the
command line.
```python
import fire
def hello(name):
return 'Hello {name}!'.format(name=name)
if __name__ == '__main__':
fire.Fire(hello)
```
Here's how we can run this from the command line:
```bash
$ python example.py World
Hello World!
```
Notice we no longer have to specify to run the `hello` function, because we
called `fire.Fire(hello)`.
##### Version 3: Using a main
We can alternatively write this program like this:
```python
import fire
def hello(name):
return 'Hello {name}!'.format(name=name)
def main():
fire.Fire(hello)
if __name__ == '__main__':
main()
```
Or if we're using
[entry points](https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points),
then simply this:
```python
import fire
def hello(name):
return 'Hello {name}!'.format(name=name)
def main():
fire.Fire(hello)
```
### Exposing Multiple Commands
In the previous example, we exposed a single function to the command line. Now
we'll look at ways of exposing multiple functions to the command line.
##### Version 1: `fire.Fire()`
The simplest way to expose multiple commands is to write multiple functions, and
then call Fire.
```python
import fire
def add(x, y):
return x + y
def multiply(x, y):
return x * y
if __name__ == '__main__':
fire.Fire()
```
We can use this like so:
```bash
$ python example.py add 10 20
30
$ python example.py multiply 10 20
200
```
You'll notice that Fire correctly parsed `10` and `20` as numbers, rather than
as strings. Read more about [argument parsing here](#argument-parsing).
##### Version 2: `fire.Fire()`
In version 1 we exposed all the program's functionality to the command line. By
using a dict, we can selectively expose functions to the command line.
```python
import fire
def add(x, y):
return x + y
def multiply(x, y):
return x * y
if __name__ == '__main__':
fire.Fire({
'add': add,
'multiply': multiply,
})
```
We can use this in the same way as before:
```bash
$ python example.py add 10 20
30
$ python example.py multiply 10 20
200
```
##### Version 3: `fire.Fire(