template-python-gladkii


Nametemplate-python-gladkii JSON
Version 1.1.3 PyPI version JSON
download
home_pagehttps://github.com/HIRO-MicroDataCenters-BV/python-service-template
SummaryWeb service template in Python for reuse.
upload_time2024-02-21 13:30:56
maintainer
docs_urlNone
authorHIRO-MicroDataCenters
requires_python>=3.12,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # template-python
Web service template in Python for reuse.

## Installation
1. If you don't have `Poetry` installed run:

```bash
pip install poetry
```

<details>
  <summary>Install Python 3.12 if it is not available in your package manager</summary>

These instructions are for Ubuntu 22.04. If you're on a different distribution,
or - God forbid! - Windows, you should adjust these accordingly.

Also, these instructions are about using Poetry with Pyenv-managed (non-system) Python.
 
### Step 1: Update and Install Dependencies
Before we install pyenv, we need to update our package lists for upgrades and new package installations. We also need to install dependencies for pyenv. 

Open your terminal and type:

```bash
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils \
tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

```


### Step 2: Install Pyenv
We will clone pyenv from the official GitHub repository and add it to our system path.

```bash
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec "$SHELL"
```


### Step 3: Install Python 3.12
Now that pyenv is installed, we can install different Python versions. To install Python 3.12, use the following command.

```bash
pyenv install 3.12
```

### Step 4: Connect Poetry to it
Do this in the template dir. Pycharm will automatically connect to it later

```bash
poetry env use ~/.pyenv/versions/3.12.1/bin/python
```
(change the version number accordingly to what is installed)

Finally, verify that Poetry indeed is connected to the proper version:
```bash
poetry enf info
```
  
</details>

2. Install dependencies:

```bash
poetry config virtualenvs.in-project true
poetry install --no-root --with dev,test
```

3. Install `pre-commit` hooks:

```bash
poetry run pre-commit install
```

4. Launch the project:

```bash
poetry run uvicorn app.main:app [--reload]
```

or do it in two steps:
```bash
poetry shell
uvicorn app.main:app

```

1. Running tests:

```bash
poetry run pytest
```

6. Building package:

```bash
poetry config pypi-token.pypi <pypi token>
poetry build
poetry publish
```

## Docker
The docker image is automatically built in GitHub Actions after pushing code/tag/pr.

You can build a docker image and create a container manually:

```bash
docker build . -t <image-name>:<image-tag>
docker run <image-name>:<image-tag>
```

https://docs.docker.com/

## Release
The release is automatically built in GitHub Actions and saved to branch gh-pages after pushing code/tag/pr.

Create the branch gh-pages and use it as a GitHub page https://pages.github.com/.  
The releases will be available at `https://github.com/<workspace>/<project>/releases/download/<app>-<version>/<app>-<version>.tgz`.  
The index will be available at `https://<workspace>.github.io/<project>/index.yaml`.  
You can use URL `https://<workspace>.github.io/<project>/` on https://artifacthub.io/.

To create a release, add a tag in GIT with the format a.a.a, where 'a' is an integer.
The release version for branches, pull requests, and other tags will be generated based on the last tag of the form a.a.a.

The Helm chart version, and Docker images versions will be automatically generated from this version in GitHub Actions.

You can build release manually:

```bash
helm package charts/<chart-name>
```

## OpenAPI schema
The OpenAPI schema will be generated automatically and saved in the release artifacts `https://github.com/<workspace>/<project>/releases/`.

## Deploy
The release is automatically deployed to Kubernetes cluster in GitHub Actions.

You can deploy it manually:

```bash
helm repo add <repo-name> https://<workspace>.github.io/<project>/
helm repo update <repo-name>
helm upgrade --install <release-name> <repo-name>/<chart-name>
```

https://helm.sh/ru/docs/

## Classy-FastAPI
Classy-FastAPI allows you to easily do dependency injection of 
object instances that should persist between FastAPI routes invocations,
e.g. database connections.
More on that (with examples) at [Classy-FastAPI GitLab page](https://gitlab.com/companionlabs-opensource/classy-fastapi
).

## GitHub Actions
GitHub Actions run tests, build and push a Docker image, creat and push a Helm chart release, deploy the project to Kubernetes cluster.

Setup secrets at `https://github.com/<workspace>/<project>/settings/secrets/actions`:
1. DOCKER_IMAGE_NAME - The name of the Docker image for uploading to the repository.
2. DOCKER_USERNAME - The username for the Docker repository on https://hub.docker.com/.
3. DOCKER_PASSWORD - The password for the Docker repository.
4. AWS_ACCESS_KEY_ID - AWS Access Key ID. https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html
5. AWS_SECRET_ACCESS_KEY - AWS Secret Access Key
6. AWS_REGION - AWS region. https://aws.amazon.com/about-aws/global-infrastructure/regions_az/
7. EKS_CLUSTER_ROLE_ARN - The IAM role's ARN in AWS, providing permissions for managing an Amazon EKS Kubernetes cluster.
8. EKS_CLUSTER_NAME - Amazon EKS Kubernetes cluster name.
9. EKS_CLUSTER_NAMESPACE - Amazon EKS Kubernetes cluster namespace.
10. HELM_REPO_URL - `https://<workspace>.github.io/<project>/`

https://docs.github.com/en/actions

You can run your GitHub Actions locally using https://github.com/nektos/act.  
Usage example:
```bash
act push -j deploy --secret-file my.secrets
```

# Collaboration guidelines
HIRO uses and requires from its partners [GitFlow with Forks](https://hirodevops.notion.site/GitFlow-with-Forks-3b737784e4fc40eaa007f04aed49bb2e?pvs=4)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/HIRO-MicroDataCenters-BV/python-service-template",
    "name": "template-python-gladkii",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.12,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "HIRO-MicroDataCenters",
    "author_email": "all-hiro@hiro-microdatacenters.nl",
    "download_url": "https://files.pythonhosted.org/packages/16/d2/11ca7024b22c756806ac230c23095e70d25818651af87279d706895dab94/template_python_gladkii-1.1.3.tar.gz",
    "platform": null,
    "description": "# template-python\nWeb service template in Python for reuse.\n\n## Installation\n1. If you don't have `Poetry` installed run:\n\n```bash\npip install poetry\n```\n\n<details>\n  <summary>Install Python 3.12 if it is not available in your package manager</summary>\n\nThese instructions are for Ubuntu 22.04. If you're on a different distribution,\nor - God forbid! - Windows, you should adjust these accordingly.\n\nAlso, these instructions are about using Poetry with Pyenv-managed (non-system) Python.\n \n### Step 1: Update and Install Dependencies\nBefore we install pyenv, we need to update our package lists for upgrades and new package installations. We also need to install dependencies for pyenv. \n\nOpen your terminal and type:\n\n```bash\nsudo apt-get update\nsudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \\\nlibreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils \\\ntk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev\n\n```\n\n\n### Step 2: Install Pyenv\nWe will clone pyenv from the official GitHub repository and add it to our system path.\n\n```bash\ngit clone https://github.com/pyenv/pyenv.git ~/.pyenv\necho 'export PYENV_ROOT=\"$HOME/.pyenv\"' >> ~/.bashrc\necho 'export PATH=\"$PYENV_ROOT/bin:$PATH\"' >> ~/.bashrc\necho 'eval \"$(pyenv init -)\"' >> ~/.bashrc\nexec \"$SHELL\"\n```\n\n\n### Step 3: Install Python 3.12\nNow that pyenv is installed, we can install different Python versions. To install Python 3.12, use the following command.\n\n```bash\npyenv install 3.12\n```\n\n### Step 4: Connect Poetry to it\nDo this in the template dir. Pycharm will automatically connect to it later\n\n```bash\npoetry env use ~/.pyenv/versions/3.12.1/bin/python\n```\n(change the version number accordingly to what is installed)\n\nFinally, verify that Poetry indeed is connected to the proper version:\n```bash\npoetry enf info\n```\n  \n</details>\n\n2. Install dependencies:\n\n```bash\npoetry config virtualenvs.in-project true\npoetry install --no-root --with dev,test\n```\n\n3. Install `pre-commit` hooks:\n\n```bash\npoetry run pre-commit install\n```\n\n4. Launch the project:\n\n```bash\npoetry run uvicorn app.main:app [--reload]\n```\n\nor do it in two steps:\n```bash\npoetry shell\nuvicorn app.main:app\n\n```\n\n1. Running tests:\n\n```bash\npoetry run pytest\n```\n\n6. Building package:\n\n```bash\npoetry config pypi-token.pypi <pypi token>\npoetry build\npoetry publish\n```\n\n## Docker\nThe docker image is automatically built in GitHub Actions after pushing code/tag/pr.\n\nYou can build a docker image and create a container manually:\n\n```bash\ndocker build . -t <image-name>:<image-tag>\ndocker run <image-name>:<image-tag>\n```\n\nhttps://docs.docker.com/\n\n## Release\nThe release is automatically built in GitHub Actions and saved to branch gh-pages after pushing code/tag/pr.\n\nCreate the branch gh-pages and use it as a GitHub page https://pages.github.com/.  \nThe releases will be available at `https://github.com/<workspace>/<project>/releases/download/<app>-<version>/<app>-<version>.tgz`.  \nThe index will be available at `https://<workspace>.github.io/<project>/index.yaml`.  \nYou can use URL `https://<workspace>.github.io/<project>/` on https://artifacthub.io/.\n\nTo create a release, add a tag in GIT with the format a.a.a, where 'a' is an integer.\nThe release version for branches, pull requests, and other tags will be generated based on the last tag of the form a.a.a.\n\nThe Helm chart version, and Docker images versions will be automatically generated from this version in GitHub Actions.\n\nYou can build release manually:\n\n```bash\nhelm package charts/<chart-name>\n```\n\n## OpenAPI schema\nThe OpenAPI schema will be generated automatically and saved in the release artifacts `https://github.com/<workspace>/<project>/releases/`.\n\n## Deploy\nThe release is automatically deployed to Kubernetes cluster in GitHub Actions.\n\nYou can deploy it manually:\n\n```bash\nhelm repo add <repo-name> https://<workspace>.github.io/<project>/\nhelm repo update <repo-name>\nhelm upgrade --install <release-name> <repo-name>/<chart-name>\n```\n\nhttps://helm.sh/ru/docs/\n\n## Classy-FastAPI\nClassy-FastAPI allows you to easily do dependency injection of \nobject instances that should persist between FastAPI routes invocations,\ne.g. database connections.\nMore on that (with examples) at [Classy-FastAPI GitLab page](https://gitlab.com/companionlabs-opensource/classy-fastapi\n).\n\n## GitHub Actions\nGitHub Actions run tests, build and push a Docker image, creat and push a Helm chart release, deploy the project to Kubernetes cluster.\n\nSetup secrets at `https://github.com/<workspace>/<project>/settings/secrets/actions`:\n1. DOCKER_IMAGE_NAME - The name of the Docker image for uploading to the repository.\n2. DOCKER_USERNAME - The username for the Docker repository on https://hub.docker.com/.\n3. DOCKER_PASSWORD - The password for the Docker repository.\n4. AWS_ACCESS_KEY_ID - AWS Access Key ID. https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html\n5. AWS_SECRET_ACCESS_KEY - AWS Secret Access Key\n6. AWS_REGION - AWS region. https://aws.amazon.com/about-aws/global-infrastructure/regions_az/\n7. EKS_CLUSTER_ROLE_ARN - The IAM role's ARN in AWS, providing permissions for managing an Amazon EKS Kubernetes cluster.\n8. EKS_CLUSTER_NAME - Amazon EKS Kubernetes cluster name.\n9. EKS_CLUSTER_NAMESPACE - Amazon EKS Kubernetes cluster namespace.\n10. HELM_REPO_URL - `https://<workspace>.github.io/<project>/`\n\nhttps://docs.github.com/en/actions\n\nYou can run your GitHub Actions locally using https://github.com/nektos/act.  \nUsage example:\n```bash\nact push -j deploy --secret-file my.secrets\n```\n\n# Collaboration guidelines\nHIRO uses and requires from its partners [GitFlow with Forks](https://hirodevops.notion.site/GitFlow-with-Forks-3b737784e4fc40eaa007f04aed49bb2e?pvs=4)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Web service template in Python for reuse.",
    "version": "1.1.3",
    "project_urls": {
        "Homepage": "https://github.com/HIRO-MicroDataCenters-BV/python-service-template",
        "Repository": "https://github.com/HIRO-MicroDataCenters-BV/python-service-template"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04cfaeae67d6978075a377d6a55d212a58c8891d1f0c3ed9a11fba4d852e28db",
                "md5": "ebcf0dc8e524f3da145b6b4d2158a8e6",
                "sha256": "1b43f93804107da72a192b09f68b6f99d05bf8f5d347079c0b4710f7c7c42019"
            },
            "downloads": -1,
            "filename": "template_python_gladkii-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ebcf0dc8e524f3da145b6b4d2158a8e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12,<4.0",
            "size": 6755,
            "upload_time": "2024-02-21T13:30:55",
            "upload_time_iso_8601": "2024-02-21T13:30:55.455031Z",
            "url": "https://files.pythonhosted.org/packages/04/cf/aeae67d6978075a377d6a55d212a58c8891d1f0c3ed9a11fba4d852e28db/template_python_gladkii-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "16d211ca7024b22c756806ac230c23095e70d25818651af87279d706895dab94",
                "md5": "db6c73ee54d3cf9d8efcbc121084ad05",
                "sha256": "bfc31270002fadf77e4ba4985bf6a24d6f34e45f857ab7484a938290f729e8f7"
            },
            "downloads": -1,
            "filename": "template_python_gladkii-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "db6c73ee54d3cf9d8efcbc121084ad05",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12,<4.0",
            "size": 9646,
            "upload_time": "2024-02-21T13:30:56",
            "upload_time_iso_8601": "2024-02-21T13:30:56.990931Z",
            "url": "https://files.pythonhosted.org/packages/16/d2/11ca7024b22c756806ac230c23095e70d25818651af87279d706895dab94/template_python_gladkii-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-21 13:30:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HIRO-MicroDataCenters-BV",
    "github_project": "python-service-template",
    "github_not_found": true,
    "lcname": "template-python-gladkii"
}
        
Elapsed time: 0.17776s