0

I want to build a CLI application in Python for some utility scripts I frequently have to run. Being a big fan of FastAPI, I checked out Typer, and it looks really cool, but Click also looks like a good pick.

I have arguments that specify date/time in my app, and I was wondering if there's any easy way for me to parse time expressions in a similar manner to how go duration strings work (while also accepting regular timestamps). Specifically, I really liked how Docker does this:

From Docker documentation

You can specify the date as an RFC 3339 date, a UNIX timestamp, or a Go duration string (e.g. 1m30s, 3h). Besides RFC3339 date format you may also use RFC3339Nano, 2006-01-02T15:04:05, 2006-01-02T15:04:05.999999999, 2006-01-02Z07:00, and 2006-01-02. The local timezone on the client will be used if you do not provide either a Z or a +-00:00 timezone offset at the end of the timestamp. When providing Unix timestamps enter seconds[.nanoseconds], where seconds is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a fraction of a second no more than nine digits long.

I was wondering if there are any utilities that'll let me easily do this. I found this question and I can work with it, but I was wondering if there's some tool that also supports timestamps out of the box, or that integrates with Typer/Click better.


Yoav
  • 1
  • 3

0 Answers0