Giter VIP home page Giter VIP logo

python-template's Introduction

Python Template

This is my template for new Python projects. The template is can be installed with cookiecutter and it's meant for developing inside a container using VS Code Dev Containers extension.

Quick start

If you're familiar with both cookiecutter and Dev Containers, this may be all you need:

cookiecutter https://github.com/tjkemp/python-template.git

Otherwise, check instructions further down the document.

Features

  • VS Code devcontainer configured with Python 3.11 and nice settings,
  • ruff and black for linting and formatting,
  • pytest for testing,
  • pipx, pip-tools,
  • pre-commit,
  • just to run all sorts of maintenance tasks.

Background

The repository started as a compilation of Python coding style recommendations. Since then Python tooling has improved and I realized most of the style considerations can (and should) be automated away. With a nice formatter and linter there's almost no need to worry about style anymore.

Installing all this new tooling can be quite a bit of work though, so this repository is turning into a template for new Python projects with everything set up the way I like it. I hope you find it useful as well. Let me know if it works or not. Otherwise I will probably be updating it about twice a year.

How to Use the Template

Requirements:

  • cookiecutter (install with pip install --user cookiecutter)
  • Visual Studio Code (not strictly required, but without it you need set up a Python environment and install all the tooling manually)
  • Tested on Linux (Ubuntu), should work on Windows 10 and Mac as well

Step 1. Run cookiecutter

Run cookiecutter with the url of this repository as an argument in the directory where you want to create the project directory.

cookiecutter https://github.com/tjkemp/python-template.git

Cookiecutter will ask you a few questions. The default values are shown in brackets.

username [username]: username
project_name [My Python Project]: My Python Project
project_slug [my-python-project]: my-python-project
python_version [3.11]: 3.11

This would create directory named whatever you input as "project_slug". In this case it would be "my-python-project".

Step 2. Start VS Code

Next enter the project directory and run code . to start VS Code. When VS Code starts, it will ask you if you want to open the project in a devcontainer. Select Reopen in Container.

$ cd my-python-project
$ code .

All the dependencies should be installed automatically. If you get an error message, try running just install in the terminal inside the container.

Step 3. Initialize git repository

This step is optional. If you want to use git, run the following commands in the terminal inside the container.

$ git init
$ git add .
$ git commit -m "Initial commit"

Everything should be set up. Start coding!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.