Fn Project: build your Python function offline

Denis Makogon
2 min readFeb 22, 2019

--

One of the most important programming languages we care a lot about is Python. Not so long ago we published a new FDK Python 0.1.1. If you haven’t heard about that please read one of the latest blog posts, you may find it very useful.

Fn CLI before 0.5.52

Before 0.5.52, during every Python function build the CLI was attempting to download the dependencies from public index PYPI. Unfortunately, not all dependencies available publicly, therefore, developers had to write their own Dockerfile in order to install a function’s dependencies using internal artifactories. That’s fine and suppose to be expected UX, however, we’d like to make developer’s life easier.

A new feature in 0.5.52 — cached dependencies

In Fn CLI v0.5.52 we introduced a new feature for Python function builds. Starting this version the CLI will look for a special directory: .pip_cache . This folder is a placeholder for a function’s dependencies.

Assume you have a python function that does have the requirement.txt file that holds dependencies references. With the following command on your machine you can download all dependencies:

pip download -r requirements.txt -d .pip_cache

as the result, a new folder will be created. This folder contains eggs/wheels for each of the dependencies mentioned in requirements.txt .

Please note that Fn CLI will need both requirements.txt and .pip_cache in order to make the build successful, meaning it is necessary to use the same file with dependencies references while downloading eggs/wheels and building a function.

So, the regular flow looks like:

fn init --runtime python
pip download -r requirements.txt -d .pip_cache
fn --verbose build

As you may notice nothing much has changed, the only thing that you need to do, if you like of course, is to download the dependencies, Fn CLI will pick and use that folder automatically.

Pros and no Cons

Pros. This feature is very useful to those developers who had to work behind corporate firewalls and with internal artifactories because they wouldn’t need to adjust the CLI or writing their own Dockerfiles.

No cons. That’s true, as Fn approaches its GA release all changes that landing into master branches of all components are backwards-compatible. The change for the Fn CLI is not an exception. Despite backwards-compatibility, offline builds feature was introduced for the sake of better UX for those developers who’d like to remain their development habits. Another thing is that we’d like to be as native as possible to programming language tools like dependencies management system, etc.

If you like this post, you may find the following links useful as a general follow-up on this post:

Finally, join the Fn Army on Slack!

--

--