Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Worldtime-py is a Python wrapper for . It is able to search through the endpoints of the API to find the closest location if the exact one could not be found. It reduces the strain and the difficulty of getting the time for the location desired.
is a JSON API for obtaining the current time in, and related data about, a timezone. It gives data suh as the UTC offset, whether that timezone is in Daylight Savings Time (DST), offset, etc.
This library can be installed by using pip install worldtimepy
. Doing so will automatically install all requirements.
This library requires you to have , , and . All of those can be installed using pip
.
This is the main class through which you should interact with the API.
.locations
Has all existing locations from WorldtimeAPI.
return list
.from_ip(ip: str='') -> TimeInfo
optional argument: ipTakes an IP and returns a corresponding TimeInfo object with timezone information for that IP. If no IP is provided, it will use the requesting IP.
return TimeInfo
.find_by_name(name: str) -> list
Takes a string and returns a list of strings for all locations that contain that name.
return list
.search(name: str) -> str
Takes a country name or a city name and tries to find it in the database. It returns a string that can be used by
get_location()
.
Warning: This function iterates through different databases to try and locate the query. It may be slow.
return string
.get_location(location: str) -> object
Takes a proper location taken from
search
orfind_by_name
and returns a TimeInfo object.
return TimeInfo
.refresh()
Gathers new data for
self.locations
.
No return
This class takes a location found through one of the other methods and makes an object with information for that timezone. You can use any location from worldtime.WorldTime().locations here.
Alternatively, if you set ip to True, you may provide an IPv4 address on to_get to get time information for that IP. If ip is set to True and nothing is given to to_get, the machine's IP will be used.
Printing or turning this object into a string returns a prettier string containing time information.
2021-06-11 00:14:14.378300 UTC-0700
.result
Full json pulled from the API.
return dict
.week_day
Returns current day of the week.
return int
.year_day
Returns current day of the year.
return int
.week_number
Returns current number of the week of the year.
return int
.datetime
Returns an aware .
return datetime
.datetime_str
Returns a string version of a datetime object.
return str
.abbreviation
Returns a string representing the abbreviated format of the timezone. E.g. 'PST'
return str
.is_dst
Returns whether timezone is in daylight savings time.
return bool
.dst_offset
.dst_from
.dst_until
.unixtime
Returns a unix like time integer.
return int
.utc
Returns the UTC time..
return str
.utc_offset
.raw_offset
FAQs
A wrapper for WorldtimeAPI with search functionality.
We found that worldtimepy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.