4259 links
  • Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
search: tag:python — newest first
  • safety · PyPI
    March 9, 2023 - permalink - https://pypi.org/project/safety/
    python scan security
  • Note: pas besoin de requirements.txt en local si on a un setup.py

    virtualenv venv
    . venv/bin/activate
    pip install --editable .

    May 24, 2022 - permalink - https://links.infomee.fr/shaare/ruUKGA
    dev python
  • Auto activate and deactivate python venv using zsh - DEV Community

    python_venv() {
    MYVENV=./venv
    # when you cd into a folder that contains $MYVENV
    [[ -d $MYVENV ]] && source $MYVENV/bin/activate > /dev/null 2>&1
    # when you cd into a folder that doesn't
    [[ ! -d $MYVENV ]] && deactivate > /dev/null 2>&1
    }
    autoload -U add-zsh-hook
    add-zsh-hook chpwd python_venv

    May 20, 2022 - permalink - https://dev.to/moniquelive/auto-activate-and-deactivate-python-venv-using-zsh-4dlm
    nomarkdown python venv zsh
  • Regular Expression HOWTO — Python 3.10.4 documentation

    named group

    May 18, 2022 - permalink - https://docs.python.org/3/howto/regex.html
    group named python re
  • IPAM — pynetbox 6.6.2.dev7+g0f1e588 documentation
    May 4, 2022 - permalink - https://pynetbox.readthedocs.io/en/latest/IPAM.html
    ipam lib netbox network python
  • GitHub - Textualize/rich: Rich is a Python library for rich text and beautiful formatting in the terminal.
    • https://pypi.org/project/simple-term-menu/
    • https://click.palletsprojects.com/en/8.1.x/
    May 4, 2022 - permalink - https://github.com/Textualize/rich
    color format python terminal
  • Regardez "Reuven M. Lerner - Practical decorators - PyCon 2019" sur YouTube

    You want to really understand decorators? Watch this video!

    boilerplate:

    import functools
    
    def decorator(func):
        @functools.wraps(func)
        def wrapper_decorator(*args, **kwargs):
            # Do something before
            value = func(*args, **kwargs)
            # Do something after
            return value
        return wrapper_decorator
    
    • https://realpython.com/primer-on-python-decorators/
    February 11, 2022 - permalink - https://youtu.be/MjHpMCIvwsY
    decorators python
  • Specifications — The Hitchhiker's Guide to Packaging 1.0 documentation

    When you want to publish a beta version, you can use a special tag that won't be proposed to client using pip install package --upgrade
    example :
    current version = 3.0.1
    next version = 3.1.0

    I can tag with 3.1.0-alpha.1

    pip install --upgrade won't upgrade to this version but pip install package==3.1.0-alpha.1 will

    February 7, 2022 - permalink - https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/specification.html
    python semver
  • python - Django template can't loop defaultdict - Stack Overflow

    django template does not like defaultdict, 2 solutions:
    1) set default_factory to None
    or
    2) cast defaultdict to a simpledict

    "The template variable resolution algorithm in Django will attempt to resolve new_data.items as new_data['items'] first, which resolves to an empty list when using defaultdict(list)."

    December 29, 2021 - permalink - https://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict
    defaultdict django python
  • Show some equivalent list comprehensions in filter examples · Issue #1068 · pallets/jinja · GitHub
    # filter out all elements not with x > 5
    a = [el for el in data if el['x'] > 5]
    
    # get all the 'c' attributes as a list
    b = [el['c'] for el in data]
    
    # get all the 'c' attributes for the elements with x > 5
    c = [el['c'] for el in data if el['x'] > 5]
    
    In Jinja2:
    
    a: {{ data | selectattr('x', 'gt', 5) | list }}
    b: {{ data | map(attribute='c') | list }} 
    c: {{ data | selectattr('x', 'gt', 5) | map(attribute='c') | list }} 
    
    September 24, 2021 - permalink - https://github.com/pallets/jinja/issues/1068
    ansible comprehension list python
  • OSX crash complaining of operation `in progress in another thread when fork() was called` · Issue #32499 · ansible/ansible · GitHub

    Ce truc obscur qui t'arrive et où la solution se trouve au fond d'une PR

    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

    August 4, 2021 - permalink - https://github.com/ansible/ansible/issues/32499
    ansible mac python
  • python - How to search and replace text in a file? - Stack Overflow

    Sometime you cant use sed :(

    Read in the file

    with open('file.txt', 'r') as file :
    filedata = file.read()

    Replace the target string

    filedata = filedata.replace('ram', 'abcd')

    Write the file out again

    with open('file.txt', 'w') as file:
    file.write(filedata)

    July 7, 2021 - permalink - https://stackoverflow.com/questions/17140886/how-to-search-and-replace-text-in-a-file
    nomarkdown python replace
  • Creating the Perfect Python Dockerfile | by Luis Sena | May, 2021 | Medium
    May 21, 2021 - permalink - https://luis-sena.medium.com/creating-the-perfect-python-dockerfile-51bdec41f1c8
    docker gunicorn python
  • pantsbuild/pex: A library and tool for generating .pex (Python EXecutable) files
    May 12, 2021 - permalink - https://github.com/pantsbuild/pex
    packaging python
  • jazzband/pip-tools: A set of tools to keep your pinned Python dependencies fresh.

    python dependency management with lock file

    May 12, 2021 - permalink - https://github.com/jazzband/pip-tools
    pip python
  • Welcome to Invoke! — Invoke documentation
    March 17, 2021 - permalink - http://www.pyinvoke.org/
    cli invoke python tools
  • Note: debug python terminal

    ++++++++++++++++++++++
    Version avec interface cmd
    ++++++++++++++++++++++

    Prérequis :

    pip install pudb

    Pour docker, dans le docker compose ajouter

    stdin_open: true
    tty: true
    Faire docker attach container_name

    Comment break/debug :

    Là où on veut break, il suffit de coller cette ligne : import pudb; pu.db

    Dans le terminal où on a fait docker attach on doit voir l'interface de pudb

    ++++++++++++++++++++++
    Version + simple
    ++++++++++++++++++++++
    Prérequis : python 3.7

    Pour docker, dans le docker compose ajouter

    stdin_open: true
    tty: true
    Faire docker attach container_name

    Comment break/debug :

    breakpoint()

    Dans le terminal où on a fait docker attach on doit voir un prompt

    On peut print les variables
    "continue" pour continuer

    February 12, 2021 - permalink - https://links.infomee.fr/shaare/lTcZoA
    debug pudb python terminal
  • GitHub - zestyping/q: Quick and dirty debugging output for tired programmers. ⛺
    January 30, 2021 - permalink - https://github.com/zestyping/q
    debug lazy python
  • colorama · PyPI
    January 8, 2021 - permalink - https://pypi.org/project/colorama/
    color python
  • Advanced usage of Python requests - timeouts, retries, hooks
    December 13, 2020 - permalink - https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/
    python requests retry
  • Python logging - under the hood
    November 30, 2020 - permalink - https://blog.urbanpiper.com/understanding-python-logging-library/
    log python
  • Rate limiting using Python and Redis
    November 14, 2020 - permalink - https://www.hackdoor.io/articles/rate-limiting-using-python-and-redis-9b7dbce8c7a5
    python rate ratelimiter
  • 73 Examples to Help You Master Python's f-strings
    November 14, 2020 - permalink - https://miguendes.me/73-examples-to-help-you-master-pythons-f-strings
    python string
  • Time zones | Django documentation | Django
    November 6, 2020 - permalink - https://docs.djangoproject.com/en/3.1/topics/i18n/timezones/
    django python timezone
  • python - Displaying a timedelta object in a django template - Stack Overflow

    Here's my filter code

    from django import template

    register = template.Library()

    @register.filter()
    def smooth_timedelta(timedeltaobj):
    """Convert a datetime.timedelta object into Days, Hours, Minutes, Seconds."""
    secs = timedeltaobj.total_seconds()
    timetot = ""
    if secs > 86400: # 60sec * 60min * 24hrs
    days = secs // 86400
    timetot += "{} days".format(int(days))
    secs = secs - days*86400

    if secs > 3600:
        hrs = secs // 3600
        timetot += " {} hours".format(int(hrs))
        secs = secs - hrs*3600
    
    if secs > 60:
        mins = secs // 60
        timetot += " {} minutes".format(int(mins))
        secs = secs - mins*60
    
    if secs > 0:
        timetot += " {} seconds".format(int(secs))
    return timetot
    

    Then in my template I did

    {% load smooth_timedelta %}

    {% timedeltaobject|smooth_timedelta %}

    October 29, 2020 - permalink - https://stackoverflow.com/questions/16348003/displaying-a-timedelta-object-in-a-django-template
    django filter python
  • Note: python natural sort

    def atoi(text):
    return int(text) if text.isdigit() else text

    def natural_keys(text):
    return [ atoi(c) for c in re.split(r'(\d+)', text) ]

    my_list.sort(key=natural_keys)

    October 9, 2020 - permalink - https://links.infomee.fr/shaare/6OC8rw
    python sort
  • Everything You Need to Know About Python's Namedtuples
    October 4, 2020 - permalink - https://miguendes.me/everything-you-need-to-know-about-pythons-namedtuples-ckfim70u102jbots197jn0zmh#why-should-i-use-namedtuples
    data namedtuple python type
  • typing — Support for type hints — Python 3.8.6 documentation
    October 4, 2020 - permalink - https://docs.python.org/3/library/typing.html
    python typing
  • Making Concurrent HTTP requests with Python AsyncIO | LAAC Technology
    October 4, 2020 - permalink - https://www.laac.dev/blog/concurrent-http-requests-python-asyncio/
    async python
  • simple-term-menu · PyPI

    Au top pour faire des petits helper en cmd line

    October 2, 2020 - permalink - https://pypi.org/project/simple-term-menu/
    interactif menu python
  • Primer on Python Decorators – Real Python
    September 17, 2020 - permalink - https://realpython.com/primer-on-python-decorators/#debugging-code
    decorator python
  • Note: str to bool

    from distutils.util import strtobool

    bool(strtobool('true'))

    FOO = bool(strtobool(os.environ['FOO']))

    September 7, 2020 - permalink - https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool
    boolean python
  • Benchmarks - FastAPI
    September 2, 2020 - permalink - https://fastapi.tiangolo.com/benchmarks/
    async fastapi python web
  • How to hide output of subprocess in Python 2.7 - Stack Overflow

    retcode = subprocess.call(['echo', 'foo'], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

    July 30, 2020 - permalink - https://stackoverflow.com/questions/11269575/how-to-hide-output-of-subprocess-in-python-2-7
    null python stdout
  • Welcome to Click — Click Documentation (7.x)
    July 8, 2020 - permalink - https://click.palletsprojects.com/en/7.x/
    arg python
  • JSON Schema | The home of JSON Schema
    June 4, 2020 - permalink - https://json-schema.org/
    json python validation
  • pytz - World Timezone Definitions for Python — pytz 2014.10 documentation
    May 29, 2020 - permalink - http://pytz.sourceforge.net/
    python timezone
  • Logging Cookbook — Python 3.8.3rc1 documentation
    May 14, 2020 - permalink - https://docs.python.org/3/howto/logging-cookbook.html
    cookbook log python
  • Apache Hadoop Amazon Web Services support – Working with IAM Assumed Roles
    April 23, 2020 - permalink - https://hadoop.apache.org/docs/current/hadoop-aws/tools/hadoop-aws/assumed_roles.html#AccessDeniedException_.2B_AmazonDynamoDBException
    assume hadoop python role spark
  • Apache Hadoop Amazon Web Services support – Working with IAM Assumed Roles
    April 22, 2020 - permalink - https://hadoop.apache.org/docs/current/hadoop-aws/tools/hadoop-aws/assumed_roles.html
    assume aws hadoop python role spark
  • GitHub - davidhalter/jedi-vim: Using the jedi autocompletion library for VIM.
    April 22, 2020 - permalink - https://github.com/davidhalter/jedi-vim
    python vim
  • How to Make a Discord Bot in Python – Real Python
    April 21, 2020 - permalink - https://realpython.com/how-to-make-a-discord-bot-python/#using-utility-functions
    bot discord python
  • Speed Up Your Python Program With Concurrency – Real Python
    April 21, 2020 - permalink - https://realpython.com/python-concurrency/#synchronous-version
    async await cpu python thread
  • GitHub - containrrr/watchtower: A process for automating Docker container base image updates.

    un container qui va update les autres containers si une image plus récente a été trouvée (stop, rm, pull, recreate)
    Pratique sur serveur perso pour les choses qui tournent en latest
    Implémentation en Go, il y a le pendant python ici : https://github.com/pyouroboros/ouroboros

    April 11, 2020 - permalink - https://github.com/containrrr/watchtower
    auto docker go python update
  • Note:

    datetime.date.today().strftime("%Y-%m-%d")
    datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    March 24, 2020 - permalink - https://links.infomee.fr/shaare/Aw6ttQ
    date python
  • Pluralsight Tech Blog | Porting Flask to FastAPI for ML Model Serving
    December 26, 2019 - permalink - https://www.pluralsight.com/tech-blog/porting-flask-to-fastapi-for-ml-model-serving/
    ds python
  • Using Python Threading and Returning Multiple Results (Tutorial) | Shane Lynn
    October 18, 2019 - permalink - https://www.shanelynn.ie/using-python-threading-for-multiple-results-queue/
    python thread
  • GitHub - MichaelAquilina/zsh-autoswitch-virtualenv: 🐍 ZSH plugin to automatically switch python virtualenvs and Pipenvs as you move between directories
    October 10, 2019 - permalink - https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv
    plugin python venv
  • GitHub - jkehler/awslambda-psycopg2
    September 2, 2019 - permalink - https://github.com/jkehler/awslambda-psycopg2
    aws lambda postgresql psycopg2 python
  • Writing a Kubernetes Operator in Python without frameworks and SDK

    simple example on how to write a kubernetes operator

    August 16, 2019 - permalink - https://medium.com/flant-com/kubernetes-operator-in-python-451f2d2e33f3
    k8s operator python
▼ Load 50 more