Differences between revisions 3 and 26 (spanning 23 versions)
Revision 3 as of 2016-08-25 18:25:37
Size: 615
Editor: SamatJain
Comment:
Revision 26 as of 2021-04-09 17:46:53
Size: 3906
Editor: SamatJain
Comment: NumPy reorg
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from Python
<<TableOfContents>>

[[CodingStyle/Python]] is another relevant page. Also:

<<FullSearchCached(t:ProgrammingLanguages/Python)>>

<<Navigation(children)>>
Line 8: Line 17:
python3-venv
Line 9: Line 19:
python-wheel
Line 13: Line 22:
== cffi == == Neat Web frameworks ==
Line 15: Line 24:
https://github.com/SimonSapin/azureblur/tree/master/azureblur [[http://aspen.io|aspen.io]]. Filesystem-based dispatch library. Used by Liberapay.
Line 17: Line 26:
[[http://stackoverflow.com/questions/37881503/how-do-i-convert-a-numpy-nd-array-to-a-cffi-c-array-and-back-again|python - How do I convert a numpy ND-array to a CFFI C++ array and back again? - Stack Overflow]] == Neat packages ==
Line 19: Line 28:
[[http://stackoverflow.com/questions/23056057/why-is-cffi-so-much-quicker-than-numpy/23058665#23058665|python - Why is cffi so much quicker than numpy? - Stack Overflow]] [[https://github.com/nvbn/py-backwards|nvbn/py-backwards]]: Python transcompiler. Lets you use Python 3.6 features in older versions, as old as Python 2.7.

[[https://github.com/asottile/future-fstrings|asottile/future-fstrings]]. Allows formatted string literals (AKA f-strings) in Python 2.7–3.5 by hacking built-in codecs.

[[https://github.com/crsmithdev/arrow/|arrow]] (relatively mature) and [[https://github.com/zachwill/moment|moment]], a port of Moment.js, are date-handling libraries with a better API than Python's stdlib.

[[https://github.com/ajalt/fuckitpy|ajalt/fuckitpy]]: Steamrolls through Python errors.

=== JSON ===

Parsing JSON without pulling your hair out…

[[https://pypi.org/project/glom/|glom]]

[[https://pypi.org/project/dpath/|dpath]]

[[https://pypi.org/project/jq/|jq]]

[[https://pypi.org/project/jmespath/|jmespath]]: used by awscli

[[https://pypi.org/project/jsons/|jsons]]: Serialize from and to Python objects, works with dataclasses and typed Python.

https://github.com/ltworf/typedload

[[https://github.com/bogdandm/json2python-models|json2python-models]]: Create dataclasses automatically from JSON files

=== Logging ===

Colored logging:

 * [[https://loguru.readthedocs.io/|loguru]]: Easy Python logging. Used by FlexGet.
 * [[https://rich.readthedocs.io/en/latest/logging.html|rich's logging handler]]: part of rich formatting library

=== Debugging ===

 * [[https://github.com/cknd/stackprinter|stackprinter]]: Debugging friendly stacktrace printing

== Compilers ==

[[http://nuitka.net/|Nuitka]]: Python native-code compiler, binary will still link to libpython.

== Typing ==

[[https://github.com/ambv/retype|ambv/retype]]: Re-applies type annotations from *.pyi stubs to a codebase.

For reference:

 * [[https://www.python.org/dev/peps/pep-0591/|PEP-591: Final and @final]]
 * [[https://www.python.org/dev/peps/pep-0589/|PEP-589: Typing for nested dictionaries]]

== Porting projects from Python 2 to Python 3 ==

=== Backports ===

==== subprocess ====

[[https://github.com/google/python-subprocess32|python-subprocess32]]: Backport of Python 3.2 `subprocess` module to 2.7. Use:

{{{#!highlight python numbers=off
if os.name == 'posix' and sys.version_info[0] < 3:
    import subprocess32 as subprocess
else:
    import subprocess
}}}

Can serve as a complete replacement for Python 2.7's `subprocess` module.

=== 2to3 libraries ===

 * [[http://python-future.org/|python-future]]
 * [[https://pythonhosted.org/six/|six]], along with [[https://python-modernize.readthedocs.io/|python-modernize]]

=== Guides ===

 * [[https://portingguide.readthedocs.io/en/latest/index.html|The Conservative Python 3 Porting Guide]]
 * [[https://docs.python.org/3/howto/pyporting.html|Porting Python 2 Code to Python 3]]

=== Notes ===

 * [[https://docs.python.org/3/howto/sorting.html#the-old-way-using-the-cmp-parameter|Sorting and using Python 3.2's funcutils.cmp_to_key()]]

== Packaging ==

=== requirements.txt ===

{{{
PyYAML ~= 5.3 # means >= V.N, == V.*
}}}

For more information, see:

 * [[https://pip.pypa.io/en/stable/reference/pip_install/#example-requirements-file|pip documentation: Example requirements file]]
 * [[https://www.python.org/dev/peps/pep-0440/#compatible-release|PEP 440: Version Identification and Dependency Specification: Compatible release]]

CodingStyle/Python is another relevant page. Also:

Development packages for Debian

Current for Ubuntu 16.04.

fabric
python-pip
python3-venv
python3-pip
python-wheel-common

Neat Web frameworks

aspen.io. Filesystem-based dispatch library. Used by Liberapay.

Neat packages

nvbn/py-backwards: Python transcompiler. Lets you use Python 3.6 features in older versions, as old as Python 2.7.

asottile/future-fstrings. Allows formatted string literals (AKA f-strings) in Python 2.7–3.5 by hacking built-in codecs.

arrow (relatively mature) and moment, a port of Moment.js, are date-handling libraries with a better API than Python's stdlib.

ajalt/fuckitpy: Steamrolls through Python errors.

JSON

Parsing JSON without pulling your hair out…

glom

dpath

jq

jmespath: used by awscli

jsons: Serialize from and to Python objects, works with dataclasses and typed Python.

https://github.com/ltworf/typedload

json2python-models: Create dataclasses automatically from JSON files

Logging

Colored logging:

Debugging

Compilers

Nuitka: Python native-code compiler, binary will still link to libpython.

Typing

ambv/retype: Re-applies type annotations from *.pyi stubs to a codebase.

For reference:

Porting projects from Python 2 to Python 3

Backports

subprocess

python-subprocess32: Backport of Python 3.2 subprocess module to 2.7. Use:

if os.name == 'posix' and sys.version_info[0] < 3:
    import subprocess32 as subprocess
else:
    import subprocess

Can serve as a complete replacement for Python 2.7's subprocess module.

2to3 libraries

Guides

Notes

Packaging

requirements.txt

PyYAML ~= 5.3  # means >= V.N, == V.*

For more information, see:

SamatsWiki: ProgrammingLanguages/Python (last edited 2021-04-09 17:46:53 by SamatJain)