How to sort results from a sqlalchemy based orm.
.order_by(model.Entry.amount.desc())
I needed this to enable paging on my thoughts api.
All posts with the tag "python"
How to sort results from a sqlalchemy based orm.
.order_by(model.Entry.amount.desc())
I needed this to enable paging on my thoughts api.
I love rich inspect. It’s one of my most often used features of rich. It gives you a great human readable insight into python object instances.
>>> from rich import inspect >>> text_file = open("foo.txt", "w") >>> inspect(text_file)
I have a pyflyby entry for it so that I can just run it ang get automatic imports. To not clash with the standard library inspect, which is quite useful on it’s own, I have aliased it to rinspect.
In flask apps I often get a 404 for routes with a trailing slash. This Stack Overflow post shows how to configure flask to allow trailing slashes on some or all routes.
Getting request headers in fastapi has a pretty nice stetup, it allows you to get headers values as function arguments,
I was able to use headers to detect if a request was made from htmx or not.
If the request was made from htmx, then we want a html format, otherwise I’m probably hitting the api programatically from something like curl or python
1j01 created a complete working clone of ms paint in the terminal using the textual framework. It’s incredible.
As the title states sqlite-utils now supports plugins. I dug in just a bit and Simon implemented this completely with entrypoints, no framework or library at all.
I am creating this post from a desktop app that I created in 3 lines.
sqlalchemy server_defaults end up as defaults in the database when new values are inserted.
A feature of jinja that I just discovered is including sub templates. Here is an example from the docs.
{% include 'header.html' %} Body goes here. {% include 'footer.html' %}
And inside of my thoughts project I used it to render posts.
<ul id='posts'> {% for post in posts.__root__ %} {% include 'post_item.html' %} {% endfor %} </ul>
note that post_item.html automatically inherits the post variable.
A guide to add Jinja2Templates to fastapi.
Mounting static files in fastapi.
Here is a snippet provided by @tiangolo to store the users jwt inside of a session cookie in fatapi. This was written in feb 12, 2020 and admits that this is not a well documented part of fastapi.
It’s already in place. More or less like the rest of the security tools. And it’s compatible with the rest of the parts, integrated with OpenAPI (as possible), but probably most importantly, with dependencies.
It’s just not properly documented yet. 😞
But still, it works 🚀 e.g.
Harlequin is a pretty sweet example of what textual can be used to create. Its a terminal based sql ide for DuckDB.
To persist data in duckdb you need to first make a connection to a duck db database.
con = duckdb.connect('file.db')
Then work off of the connection con rather than duckdb.
duckdb can just query any pandas dataframe that is in memory.
I tried running it against a list of objects and got this error. Great error message that gives me supported types right in the message.
pytest-subtests is a package to register multiple subtests within a similar test function.
![[None]]
When setting up a new machine, vm, docker image you might be installing command line tools from places like pip. They will often put executables in your ~/.local/bin directory, but by default your shell is not looking in that directory for commands.
WARNING: The script dotenv is installed in '/home/falcon/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
To solve this you need to add that directory to your $PATH.
export PATH=$PATH:~/.local/bin
To make this change permanant add this line to your shell’s init script, which is likely something like ~/.bashrc or ~/.zshrc.
Very inspiring textual project to check out how they set up the ui. Their intro video has a pretty epic dev experience.
wsrepl is an epic websocket repl built in python on the textual framework.