# Python Programming Language

- Page: https://shared.btbytes.com/p/python
- Date: 2020-01-09
- Tags: python, programming-language

## My Python Stuff

- [My PyCon 2010 notes](https://www.btbytes.com/pycon2010/)
- [See posts and notebooks tagged #python](https://www.btbytes.com/tags.html#python)
	- [My Happy Python Workflow](https://www.btbytes.com/posts/2020-05-06-06-happy-python)
	- [Getting Out of the Programming Goldilocks Zone](https://www.btbytes.com/posts/2020-05-14-1-getting-out-of-goldilocks-zone)

## Meta

- [Awesome Python](https://awesome-python.com/)

## Advanced Python

[dabeaz-course/python-mastery: Advanced Python Mastery (course by David Beazley)](https://github.com/dabeaz-course/python-mastery)

## Books

* [Fundamentals of Python programming](http://web.archive.org/web/20120425093519/http://python.cs.southern.edu/pythonbook/pythonbook.pdf) (PDF) -- "... introduction to computer programming textbooks are available in PDF form for free download. University and high school students and self learners around the world have found them helpful. See the terms of use in the preface of each book."

* Intermediate Python -- "Fluent python" by Luciano Ramalho.

## Learning sources

- [Tiny-Python-3.6-Notebook/python.rst at master · mattharrison/Tiny-Python-3.6-Notebook](https://github.com/mattharrison/Tiny-Python-3.6-Notebook/blob/master/python.rst)

> "This repository contains the text for the Tiny Python 3.6 Notebook. it is a notebook containing curated examples for Python 3 as well as the new features found in Python 3.6."

## Internals

- [How virtual environments work](https://snarky.ca/how-virtual-environments-work/)
- [CPython Dynamic Dispatch Internals: How a + b Works?](https://codeconfessions.substack.com/p/cpython-dynamic-dispatch-internals)


## Developer Experience (DevEx)

[Make Python DevEx](https://tech.target.com/blog/make-python-devex) -- this is very close to how I choose to do Python development. good read. I don't have such an extensive Makefile setup.

## Debugging

- [Debugging cpython with gdb](http://podoliaka.org/2016/04/10/debugging-cpython-gdb/)
* [Martin Heinz - "Ultimate Guide to Python Debugging"](https://martinheinz.dev/blog/24) 2020-06-02. Talks a lot about logging, but there is some interesting bits about using `__repr__` and `__missing__` dunder methods.

## Profiling

- [benfred/py-spy: Sampling profiler for Python programs](https://github.com/benfred/py-spy)

* [Scalene: a high-performance, high-precision CPU and memory profiler for Python](https://news.ycombinator.com/item?id=22003368) has interleaved cross-language profiling.

* [Pyflame: A Ptracing Profiler For Python — Pyflame 1.4.0 documentation](https://pyflame.readthedocs.io/en/latest/)

## Web

- [emmett-framework/granian: A Rust HTTP server for Python applications](https://github.com/emmett-framework/granian)
- [Robyn - An async Python Framework written in Rust.](https://robyn.tech/)

## Multiprocessing

- [Stabbing yourself with a fork() in a multiprocessing.Pool full of sharks](https://codewithoutrules.com/2018/09/04/python-multiprocessing/)

## Async

- [Concurrency and async / await - FastAPI](https://fastapi.tiangolo.com/async/)

## Sublime Text

- [Flake8Lint](https://github.com/dreadatour/Flake8Lint) is infuriating but
  important plugin for sublime text. [Flake8 Rules](https://lintlyci.github.io/Flake8Rules/)


## Alternate Python implementations

- [Zippy](https://bitbucket.org/ssllab/zippy) ; [Slides](http://socalpls.org/2013nov/slides/zippy.pdf), [paper](http://thezhangwei.com/documents/oopsla113-zhang.pdf)

To Install Zippy:

```bash
hg clone https://bitbucket.org/ssllab/zippy
cd zippy
TBD
```

## Libraries


- [Deciphering Glyph :: Python Packaging Is Good Now](https://glyph.twistedmatrix.com/2016/08/python-packaging.html); August 2016.
- [Cookiecutter](https://github.com/audreyr/cookiecutter) -- A
  command-line utility that creates projects from cookie cutters (project
  templates). See [Example](https://github.com/larsyencken/pandoc-talk)
  using cookie cutter for pandoc presentations.
- [Python modules you should  know](http://tmp.devcharm.com/pages/python-modules-you-should-know)
- [20 Python Libraries You
Aren’t Using (But Should)](http://www.oreilly.com/programming/free/files/20-python-libraries-you-arent-using-but-should.pdf) [PDF] by Caleb Hattingh on O'Reilly. (broken link; sep 2024)
- [Peep](https://pypi.python.org/pypi/peep/). A "pip install" that is
  cryptographically guaranteed repeatable
- [imutils](https://github.com/jrosebr1/imutils) -- A series of
  convenience functions to make basic image processing operations such
  as translation, rotation, resizing, skeletonization, and displaying
  Matplotlib images easier with OpenCV and Python.
- [The Python Graph Gallery – Visualizing data – with Python](https://python-graph-gallery.com/)
- [Getting the Most out of Sqlite3 with Python](https://remusao.github.io/posts/2017-10-21-few-tips-sqlite-perf.html); See [dataset](https://dataset.readthedocs.io/en/latest/) and [apsw](https://github.com/rogerbinns/apsw).
- [mahmoud/awesome-python-applications: 💿 Free software that works great, which also happens to be open-source Python.](https://github.com/mahmoud/awesome-python-applications#tag-graphics)


### Data science libraries

- [agate 1.6.0 — agate 1.6.0 documentation](https://agate.readthedocs.io/en/1.6.0/)
- [dataset: databases for lazy people](https://dataset.readthedocs.io/en/latest/)
- [Python Itertools: For a faster and memory efficient code – Kanoki](https://kanoki.org/2019/02/08/python-itertools/)

## Conferences

- [PyData](http://pydata.org/nyc2013/) (NYC 2013).
- [Videos](http://pyvideo.org/category/18/pydata).

## Python3

- [The key differences between Python 2.7.x and Python 3.x with examples](http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html)
- "the not-so-simple intricacies of Python2->Python3" - [oilshell comments on Python 3 and Firefox 57 (an observation)](https://www.reddit.com/r/ProgrammingLanguages/comments/7elxlv/python_3_and_firefox_57_an_observation/dq6ixqu/)

## Pypy

- [PyPy Status Blog: The First 15 Years of PyPy — a Personal Retrospective](https://morepypy.blogspot.com/2018/09/the-first-15-years-of-pypy.html)

## Package management


- [Python packages with pyproject.toml and nothing else | Simon Willison’s TILs](https://til.simonwillison.net/python/pyproject); Jul 2023. Discovered it via [My User Experience Porting Off setup.py](https://gregoryszorc.com/blog/2023/10/30/my-user-experience-porting-off-setup.py/)
- [Python Project Tooling explained — chobeat](https://write.as/chobeat/python-project-tooling-explained); Apr 2019. [lobste.rs](https://lobste.rs/s/jrryrg/python_project_tooling_explained)

    * Poetry
    * Pipsi
    * `pyenv` (polyglot alternate is [mise](https://mise.jdx.dev/getting-started.html); is a replacement for `pyenv`, `rbenv`, `asdf`, `nvm`, etc.,)
    * not mentioned above, but see also `hatch` and `pdm`

- [Use pew, not virtualenvwrapper, for Python virtualenvs](http://planspace.org/20150120-use_pew_not_virtualenvwrapper_for_python_virtualenvs/)

- Use `twine`, and `wheel`.

- Follow the [packaging tutorial](https://packaging.python.org/tutorials/distributing-packages/)
- Use [TestPyPi](https://packaging.python.org/guides/using-testpypi/#using-test-pypi)
- Short summary of commands:

```bash
python setup.py sdist
python setup.py bdist_wheel
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
```

- [uv: An Extremely Fast Python Package Manager - YouTube](https://www.youtube.com/watch?v=gSKTfG1GXYQ), talk by Charlie Marsh of Astral.sh

## Project Managers

[Do not use requirements.txt - quanttype](https://quanttype.net/posts/2023-10-31-do-not-use-requirements.txt.html) -- instead choose Poetry, Hatch or pdm.

### Poetry

I have been using [poetry](https://python-poetry.org) for a while.

> Poetry uses the `pyproject.toml` standard, but it does not follow the standard specifying how metadata should be represented in a pyproject.toml file ([PEP 621](https://www.python.org/dev/peps/pep-0621)), instead using a custom `[tool.poetry]` table. This is partly because Poetry came out before PEP 621. -- *from pdm's documentation*

### [Hatch](https://hatch.pypa.io/latest/)

- Standardized [build system](https://hatch.pypa.io/latest/build/#packaging-ecosystem) with reproducible builds by default
- Robust [environment management](https://hatch.pypa.io/latest/environment/) with support for custom scripts
- Easy [publishing](https://hatch.pypa.io/latest/publish/) to PyPI or other indexes
- [Version management](https://hatch.pypa.io/latest/version/)
- Configurable [project generation](https://hatch.pypa.io/latest/config/project-templates/) with sane defaults
- Responsive [CLI](https://hatch.pypa.io/latest/cli/about/), ~2-3x [faster](https://github.com/pypa/hatch/blob/hatch-v1.5.0/.github/workflows/test.yml#L76-L108) than equivalent tools

### [pdm](https://github.com/pdm-project/pdm)

> Unlike Poetry and Hatch, PDM is not limited to a specific build backend; users have the freedom to choose any build backend they prefer.


## Links

- [Solving the Water Jug Problem from Die Hard 3 with TLA+ and Hypothesis](http://nchammas.com/writing/how-not-to-die-hard-with-hypothesis)
- [Writing beautiful intelligent python](https://www.youtube.com/watch?v=wf-BqAjZb8M) -- talk by Raymond Hettinger in Pycon 2015.
- [profiling - Python profiler](https://github.com/what-studio/profiling). [HN; Aug 2015](https://news.ycombinator.com/item?id=10046719)
- [vprof - Visual Profiler](https://github.com/nvdv/vprof); flame charts, memory usage etc.,
- [Pyparallel](http://pyparallel.org/) -- "An experimental,
proof-of-concept fork of Python 3 designed to optimally exploit
multiple CPU cores, fast SSDs, NUMA architectures and 10Gb+ Ethernet
networks. Removes the limitation of the Global Interpreter Lock (GIL)
without needing to remove it at all."
- [Replacing Python: Candidates](http://roscidus.com/blog/blog/2013/06/09/choosing-a-python-replacement-for-0install/).
  A survey of various languages while keeping these considerations in
  mind: speed, binary compatibility, safety, diagnostics, ease of
  writing, shared libs, static typing, bounds of privilege, mutability,
  C interoperability and asynchronous code. OCaml appears to be the
  winner. This is written by the author of `0install`.
- [Setting up Emacs for python
  development](http://www.kurup.org/blog/2012/10/24/emacs-for-python-programming/)
  including [Pymacs](http://web.archive.org/web/20041206014046/http://pymacs.progiciels-bpi.ca/index.html),
  pyflakes, pep8, python-mode.el, python.el etc.,. Pymacs has detailed
  documentation (31pp) on their website.
- Python Tips -- [Intermediate Python](http://book.pythontips.com/en/latest/)
- Nov 2015; [Python for High performance scintific computing (disussion)](https://news.ycombinator.com/item?id=10650347)
- [Python: Generators, Coroutines, Native Coroutines and async/await | Abu Ashraf Masnun](http://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html)
-[Parallelizing a Python Function for the Extremely Lazy - tdhopper.com](http://tdhopper.com/blog/2017/Jun/07/parallelizing-a-python-function-for-the-extremely-lazy/)
- [The Little Book of Python Anti-Patterns — Python Anti-Patterns documentation](http://docs.quantifiedcode.com/python-anti-patterns/index.html)


### 2019

Via [My Python Development Environment, 2020 Edition | Jacob Kaplan-Moss](https://jacobian.org/2019/nov/11/python-environment-2020/):

  * [pipx · PyPI](https://pypi.org/project/pipx/)
  * [Poetry - Python dependency management and packaging made easy.](https://poetry.eustace.io/)
  * [VisiData](http://visidata.org/)
