Skip to content

Installation

With pip for general usage

pip is a Python package management tool. We could install all the Python packages which be managed in PyPI platform. So we also could install PyFake-API-Server via pip as below command:

pip install fake-api-server

However, it may have something problems:

  • It would install all the dependencies which may includes something you don't need.

So it recommends that installs PyFake-API-Server by pip with option to install the necessary dependencies only.

pip install "fake-api-server[<web framework>]"

The dependencies which are necessary to install decreases greatly.

What the options web framework we could use?

PyFake-API-Server uses the Python web framework to implement the API feature. It means that it would also depend on other Python package which for web development. Currrently, it supports 2 frameworks of all popular Python web framerworks --- Flask and FastAPI. So the options value we could use are: mini, flask or fastapi.

Strategy name Purpose
mini Install the minimum level dependency of Python package. It means it won't install both of web frameworks Flask or FastAPI.
flask Install the dependencies includes Flask and Gunicorn.
fastapi Install the dependencies includes FastAPI and Uvicorn.

With poetry recommended for Python developer

If you're familiar with Python, it strongly recommends that use Poetry to manage your Python project includes installing this package.

So what is Poetry ...?

If you still miss your direction about how to manage your Python project, you must try to use Poetry to do it. Poetry is a tool for managing your Python project includes the deeply complex relations of Python dependencies.

Let's quickly demonstrate the general usage of Poetry to you.

If you want to add a new dependency, in the other words, install a new Python package, it doesn't use pip, use poetry to add it.

poetry add <Python package>

How easy it is! Isn't it? It's also easy for removing dependency:

poetry remove <Python package>

So what's the difference between Poetry and pip? The major difference is Poetry could be greatly better to manage your dependencies! Let's consider a scenario. If a package A which depends on pacakge B, it would also install package B when it installs pacakge A. However, about removing this package, it's a trouble when you use pip because pip won't remove package B when you remove package A! You need to manually remove package B if you want to remove them clearly. If your project is huge, it's also a big problem of managing your project's dependencies. And the poetry is a great solution to resolve this issue. Poetry even sorts out the dependencies relations as a tree diagram and illustrate it as following:

>>> poetry show --tree --without=dev
fastapi 0.95.2 FastAPI framework, high performance, easy to learn, fast to code, ready for production
├── email-validator >=1.1.1
│   ├── dnspython >=2.0.0
│   └── idna >=2.0.0
├── httpx >=0.23.0
│   ├── certifi *
│   ├── httpcore >=0.15.0,<0.18.0
│   │   ├── anyio >=3.0,<5.0
│   │   │   ├── idna >=2.8
...

How clear it is! So Poetry is a very powerful tool for manage your Python project.

The installing command is little different with pip but be similar:

poetry add fake-api-server

It also could install necessary parts of dependencies only.

poetry add "fake-api-server[<web framework>]"

It should add one more dependency PyFake-API-Server in your configuration pyproject.toml.

With git

If you want to use the latest features of PyFake-API-Server, you could use git to clone the project's source code first.

git clone https://github.com/Chisanan232/PyFake-API-Server.git ./fake_api_server -b <git branch>

The dividing rule of git branch

It apply Trunk-base developmenet at PyFake-API-Server project and its trunk branch is master.:

demonstration

  • develop
    • Git branch: develop/**
    • Majot process: All the development should base on this branch to work. The code of this branch always be latest but also unstable.
  • master
    • Git branch: master (it's also trunk branch)
    • Majot process: The final code to release to PyPI incudes documentation. The code of this branch is stablest and it also be same as the code in PyPI.

After source code be ready, you could install it by pip.

pip install -e fake-api-server

With Docker for general usage without Python runtime environment

If your runtime environment has not installed Python and you won't use Python temporarily, you also could use Docker to enjoy PyFake-API-Server.

Download PyFake-API-Server official image as below:

docker pull fake-api-server:v0.1.0
Recommended: Use the tag to manage your Docker image

You could use command line docker pull fake-api-server without tag absolutely. But the default tag is latest. That means you cannot clear what version you have currently. So it recommends using tag to manage it and clear what version it use currently by yourself.

Verify the Docker image has been exactly installed:

docker images fake-api-server

Verify the command line feature

No matter which way to install PyFake-API-Server, it must verify whether the command line tool is ready for working or not.

fake --help

If it outputs some usage info about the command mock, congratulation! You could start to enjoy easily and quickly mock API.