A python package template that can be adapted for RAP projects

Related tags

Miscellaneous rap
Overview

Warning - this repository is a snapshot of a repository internal to NHS Digital. This means that links to videos and some URLs may not work.

Repository owner: NHS Digital Analytical Services

Email: [email protected]

To contact us raise an issue on Github or via email and will respond promptly.

rap-package-template

A python package template that can be adapted for RAP projects.

What is a package?

You can learn all about packages and why they are useful in the community-of-practice project structure and packaging guide.

Getting Started

Clone repository

To clone the repository, please see our community of practice page.

Set up environment

There are two options to set up the python enviroment:

  1. Pip using requirements.txt.
  2. Conda using environment.yml.

Users would need to delete as appropriate which set they do not need. For details, please see our virtual environments in the community of practice page.

Option 1: To run pip

Run the following command in Terminal or VScode to set up the package:

    python setup.py install
    pip install -e .
    pip install -r requirements.txt

Option 2: To run conda

Use Anaconda Prompt for the following steps:

  1. Create the environment from the environment.yml file:
    conda env create -f environment.yml

The first line of the .yml file sets the new environment's name. In this template, the name is rap.

  1. Activate the new environment:
    conda activate rap
  1. Verify that the new environment was installed correctly:
   conda env list

Package structure:

rap-package-template
│   README.md
│
├───my_project
│   │   create_publication.py
│   │   params.py
│   │
│   └───utilities
│       │   data_connections.py
│       │   field_definitions.py
│       │   processing_steps.py
|
├───reports
│   │
│   ├───input_profile
│   └───output_profile
│
└───tests
    ├───unittests
    │       │   test_data_connections.py
    │       │   test_field_definitions.py
    │       │   test_processing_steps.py
    │
    └───backtests
            test_compare_outputs.py

Some things to notice about this structure:

  • In the repository there are two files: create_publication.py and params.py. These top level files are the highest level of abstraction and should be the main place where users interact with the code.

    • The params.py file contains all of the parameters that we expect to change frequently, e.g. input data.
    • The create_publication.py file organises the steps in a simple, easy-to-understand manner that should be readable by anyone, even if they don't know python. In this way, we aim to reduce risk by make the code accessible to new staff.
  • The next level down contains the meaty parts of the code. By organising the code into logical sections, we make it easier to understand but also to maintain and test. Moreover, tucking the complex code out of the way means that users don't need to understand everything about the code all at once.

    • The data_connections.py file handles reading data in and writing data back out.
    • The field_definitions.py file contains the definitions for each of the fields (columns) derived in the process. By abstracting these definitions out of the code and making them reuseable, we achieve some great benefits. First, it becomes much easier to maintain. When the specifications change next year, we only need to make the change in one location. Next, it becomes much easier to test. We write unit tests for each of these definitions and can then reuse these definitions in many places without increasing risk.
    • The processing_steps.py file contains the core business logic.

Note that we never store passwords or any sensitive credentials in the repo to prevent the situation where it can mistakenly committed into the git. There are several ways to deal with the secret, keys and passwords such as using Git Hooks or final cleansing process before publishing.

Adapting the package

You can adapt the package to meet your own needs. The most obvious change would be to change the directory name and the name of the place where the code is kept. For example, if you were producing the National Diabetes Audit (NDA) you might change the repo to look like this:

national-diabetes-audit
│   README.md
│
├───national_diabetes_audit
│   │   create_publication.py
│   │   params.py

The same change applied to the Smoking, Drinking, and Drugs (SDD) publication might look like this:

smoking-drinking-drugs
│   README.md
│
├───smoking_drinking_drugs
│   │   create_publication.py
│   │   params.py

The python package exercises page list some steps you can follow to try adapting this package.

Link to your publication [To be modified by the user]

You should include a link to where your publication is published so people can easily see the outputs. Conversely, you should add a link in your publication to this repo's address on the public facing github.

Licence [To be modified by the user]

The XXXXXX publication codebase is released under the MIT License. The documentation is © Crown copyright and available under the terms of the Open Government 3.0 licence.

You might also like...
Data Structures and Algorithms Python - Practice data structures and algorithms in python with few small projects

Data Structures and Algorithms All the essential resources and template code nee

The tool helps to find hidden parameters that can be vulnerable or can reveal interesting functionality that other hunters miss.
The tool helps to find hidden parameters that can be vulnerable or can reveal interesting functionality that other hunters miss.

The tool helps to find hidden parameters that can be vulnerable or can reveal interesting functionality that other hunters miss. Greater accuracy is achieved thanks to the line-by-line comparison of pages, comparison of response code and reflections.

You can easily send campaigns, e-marketing have actually account using cash will thank you for using our tools, and you can support our Vodafone Cash +201090788026

*** Welcome User Sorry I Mean Hello Brother ✓ Devolper and Design : Mokhtar Abdelkreem ========================================== You Can Follow Us O

Python Project Template

A low dependency and really simple to start project template for Python Projects.

Python template for Advent of Code event

Advent of Code Python Starter A tamplate for Advent of Code write in Python. Usage The project use poetry for project manager. Clone this repository a

This repository contains Python Projects for Beginners as well as for Intermediate Developers built by Contributors.
This repository contains Python Projects for Beginners as well as for Intermediate Developers built by Contributors.

Python Projects {Open Source} Introduction The repository was built with a tree-like structure in mind, it contains collections of Python Projects. Mo

Collections of python projects
Collections of python projects

nppy, mostly contains projects written in Python. Some projects are very simple while some are a bit lenghty and difficult(for beginners) Requirements

Small projects for python beginners.

Python Mini Projects For Beginners I recently started doing the #100DaysOfCode Challenge in Python. I've used Python before, but I had switched to JS

Sathal's Python Projects Repository

Sathal's Python Projects Repository Purpose and Motivation I come from a mainly C Programming Language background and have previous classroom experien

Releases(v0.0.1)
Owner
NHS Digital
NHS Digital Public Repository
NHS Digital
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

null 18.6k Jan 2, 2023
Python for downloading model data (HRRR, RAP, GFS, NBM, etc.) from NOMADS, NOAA's Big Data Program partners (Amazon, Google, Microsoft), and the University of Utah Pando Archive System.

Python for downloading model data (HRRR, RAP, GFS, NBM, etc.) from NOMADS, NOAA's Big Data Program partners (Amazon, Google, Microsoft), and the University of Utah Pando Archive System.

Brian Blaylock 194 Jan 2, 2023
A minimalist starknet amm adapted from StarkWare's amm.

viscus • A minimalist starknet amm adapted from StarkWare's amm. Directory Structure contracts

Alucard 4 Dec 27, 2021
Beginner Projects A couple of beginner projects here

Beginner Projects A couple of beginner projects here, listed from easiest to hardest :) selector.py: simply a random selector to tell me who to faceti

Kylie 272 Jan 7, 2023
Hydralit package is a wrapping and template project to combine multiple independant Streamlit applications into a multi-page application.

Hydralit The Hydralit package is a wrapping and template project to combine multiple independant (or somewhat dependant) Streamlit applications into a

Jackson Storm 108 Jan 8, 2023
A place where one-off ideas/partial projects can live comfortably

A place to post ideas, partial projects, or anything else that doesn't necessarily warrant its own repo, from my mind to the web.

Carson Scott 2 Feb 25, 2022
A test repository to build a python package and publish the package to Artifact Registry using GCB

A test repository to build a python package and publish the package to Artifact Registry using GCB. Then have the package be a dependency in a GCF function.

null 1 Feb 9, 2022
This Python script can enumerate all URLs present in robots.txt files, and test whether they can be accessed or not.

Robots.txt tester With this script, you can enumerate all URLs present in robots.txt files, and test whether you can access them or not. Setup Clone t

Podalirius 32 Oct 10, 2022
PyPI package for scaffolding out code for decision tree models that can learn to find relationships between the attributes of an object.

Decision Tree Writer This package allows you to train a binary classification decision tree on a list of labeled dictionaries or class instances, and

null 2 Apr 23, 2022
Python Projects is an Open Source to enhance your python skills

Welcome! ???? Python Project is Open Source to enhance your python skills. You're free to contribute. ?? You just need to give us your scripts written

Tristán 6 Nov 28, 2022