Anaconda Project Documentation PDF
Anaconda Project Documentation PDF
Anaconda Project Documentation PDF
0rc5 documentation
Anaconda Project
Docs »
User guide »
Reference Edit on GitHub
Reference
The anaconda-project command works with project directories, which can
contain scripts, notebooks,
data files, and anything that is related to your
project.
.yml files are in the YAML format and follow the YAML syntax.
anaconda-project.yml , anaconda-project-local.yml ,
anaconda-project-lock.yml
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
myproject/
analyze.py
anaconda-project.yml
commands:
default:
unix: "python ${PROJECT_DIR}/analyze.py"
windows: "python %PROJECT_DIR%\analyze.py"
There are separate command lines for Unix shells (Linux and
macOS) and for Windows. You may
target only one platform, and
are not required to provide command lines for other platforms.
When you send your project to someone else, they can type
anaconda-project run to run your script.
The best part
is that anaconda-project run makes sure that all
prerequisites are set up before it runs
the script.
packages:
- redis-py
downloads:
MYDATAFILE:
url: http://example.com/bigdatafile
sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
import os
filename = os.getenv('MYDATAFILE')
if filename is None:
raise Exception("Please use 'anaconda-project run' to start this script")
with open(filename, 'r') as input:
data = input.read()
# and so on
Multiple Commands
An anaconda-project.yml can list multiple commands. Each command has a
name, and
anaconda-project run COMMAND_NAME runs the command named
COMMAND_NAME .
commands:
mycommand:
unix: "python ${PROJECT_DIR}/analyze.py"
windows: "python %PROJECT_DIR%\analyze.py"
description: "This command runs the analysis"
commands:
foo:
bokeh_app: foo
description: "Runs the bokeh app in the foo subdirectory"
bar:
notebook: bar.ipynb
description: "Opens the notebook bar.ipynb"
Notebook-specific options
Notebook commands can annotate that they contain a function
registered with Anaconda Fusion:
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
commands:
bar:
notebook: bar.ipynb
description: "Notebook exporting an Anaconda Fusion function."
registers_fusion_function: true
HTTP Commands
anaconda-project can be used to pack up web applications and
run them on a server. Web
applications include Bokeh
applications, notebooks, APIs, and anything else that communicates with
HTTP.
field:
commands:
myapp:
unix: launch_flask_app.py
description: "Launches a Flask web app"
supports_http_options: true
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
packages:
- redis-py
channels:
- conda-forge
env_specs:
default:
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
packages:
- foo
- bar
channels:
- conda-forge
python27:
description: "Uses Python 2 instead of 3"
packages:
- python < 3
channels:
- https://example.com/somechannel
To run a project using a specific env spec, use the --env-spec option:
The default env spec can be specified for each command, like this:
commands:
mycommand:
unix: "python ${PROJECT_DIR}/analyze.py"
windows: "python %PROJECT_DIR%\analyze.py"
env_spec: my_env_spec_name
Env specs can also inherit from one another. List a single
env spec or a list of env specs to inherit
from,
something like this:
env_specs:
test_packages:
description: "Packages used for testing"
packages:
- pytest
- pytest-cov
app_dependencies:
description: "Packages used by my app"
packages:
- bokeh
app_test_dependencies:
description: "Packages used to test my app"
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
commands:
default:
unix: start_my_app.py
env_spec: app_dependencies
test:
unix: python -m pytest myapp/tests
env_spec: app_test_dependencies
pip packages
Underneath any packages: section, you can add a pip:
section with a list of pip requirement
specifiers.
packages:
- condapackage1
- pip:
- pippackage1
- pippackage2
locking_enabled: true
env_specs:
default:
locked: true
env_spec_hash: eb23ad7bd050fb6383fcb71958ff03db074b0525
platforms:
- linux-64
- win-64
packages:
all:
- backports=1.0=py27_0
- backports_abc=0.5=py27_0
- bokeh=0.12.4=py27_0
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
- futures=3.0.5=py27_0
- jinja2=2.9.5=py27_0
- markupsafe=0.23=py27_2
- mkl=2017.0.1=0
- numpy=1.12.1=py27_0
- pandas=0.19.2=np112py27_1
- pip=9.0.1=py27_1
- python-dateutil=2.6.0=py27_0
- python=2.7.13=0
- pytz=2016.10=py27_0
- pyyaml=3.12=py27_0
- requests=2.13.0=py27_0
- singledispatch=3.4.0.3=py27_0
- six=1.10.0=py27_0
- ssl_match_hostname=3.4.0.2=py27_1
- tornado=4.4.2=py27_0
- wheel=0.29.0=py27_0
unix:
- openssl=1.0.2k=1
- readline=6.2=2
- setuptools=27.2.0=py27_0
- sqlite=3.13.0=0
- tk=8.5.18=0
- yaml=0.1.6=0
- zlib=1.2.8=3
win:
- setuptools=27.2.0=py27_1
- vs2008_runtime=9.00.30729.5054=0
By locking your versions, you can make your project more portable.
When you share it with someone
else or deploy it on a server or
try to use it yourself in a few months, you’ll get the same
package
versions you’ve already used for testing. If you don’t
lock your versions, you may find that your
project stops working
due to changes in its dependencies.
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
anaconda-project unlock turns off locking for all env specs and
anaconda-project lock turns on locking
for all env specs.
If locking isn’t enabled for the project or for the env spec,
there’s no need to anaconda-project update
For example:
variables:
- AMAZON_EC2_USERNAME
- AMAZON_EC2_PASSWORD
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
Now in your script, you can use os.getenv() to get these variables.
NOTE: This is a much better option than hardcoding passwords into your
script, which can be a
security risk.
stores and
encrypts the value that you enter when prompted.
variables:
# let's encrypt the password but not the username
AMAZON_EC2_USERNAME: { encrypted: false }
AMAZON_EC2_PASSWORD: { encrypted: true }
For example:
.. code-block:: yaml
variables:
ALPHA: “default_value_of_alpha”
BRAVO: null # no default for BRAVO
CHARLIE: {} # no
default for CHARLIE
# default as part of options dict, needed if you also
# want to set some
options such as ‘encrypted: true’
DELTA: { default: “default_value_of_delta” }
ECHO: { default:
“default_value_of_echo”, encrypted: true }
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
For example:
variables:
SALES_DB_PASSWORD: {
description: "The password for the sales database. Ask jim@example.com if you don't have one."
}
These variables always exist and can always be used in your Python code.
For example, to get a file
from your project directory, try this in your
Python code (notebook or script):
import os
project_dir = os.getenv("PROJECT_DIR")
my_file = os.path.join(project_dir, "my/file.txt")
Services
TIP: Services are a proof-of-concept demo feature for now.
For example, you can add a services section to your anaconda-project.yml file:
services:
REDIS_URL: redis
services:
REDIS_URL: { type: redis }
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
and you can set a default and any options a service may have:
services:
REDIS_URL:
type: redis
default: "redis://localhost:5895"
File Downloads
The downloads: section of the anaconda-project.yml file lets you define
environment variables that
point to downloaded files. For example:
downloads:
MYDATAFILE:
url: http://example.com/bigdatafile
sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
Rather than sha1, you can use whatever integrity hash you have;
supported hashes are md5 , sha1 ,
sha224 , sha256 ,
sha384 , sha512 .
NOTE: The download is checked for integrity ONLY if you specify a hash.
downloads:
MYDATAFILE:
url: http://example.com/bigdatafile
filename: myfile.csv
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
downloads:
MYDATAFILE:
url: http://example.com/bigdatafile
unzip: true
name: myproject
You can also have an icon file, relative to the project directory:
icon: images/myicon.png
To add a package:
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]
Reference — Anaconda Project 0.8.0rc5 documentation
Previous Next
https://anaconda-project.readthedocs.io/en/latest/user-guide/reference.html[09/06/2020 21:46:47]