batutils - Team Batcave Python Toolkit
A grab-bag of small, dependency-free Python utilities for working with dates and times and for everyday type juggling, originally written by Team Batcave at CCP Games.
This is a fork of ccptools, kept alive
beyond the original team's lifespan. Our two most commonly used internal packages,
datetimeutils and typeutils, had names that were too generic for PyPI and were
used in 80-90% of our other projects, so they were smooshed together into one
package.
pip install batutils
Requires Python 3.10 or newer.
What's inside
| Submodule | Formerly | What it is | Docs |
|---|---|---|---|
batutils.dtu |
datetimeutils |
Casting, parsing, formatting and shortcuts for date/time values | Date/Time Utils |
batutils.tpu |
typeutils |
Safe type evaluation, nested dict/list helpers, enums, singletons, serializers and more | Type Utils |
batutils.structs |
One-line "usual imports" for your modules | below |
Looking for a specific function? Use the task-oriented Public API index.
Quick taste
from batutils import dtu
from batutils.tpu.casting import int_eval, bool_eval
from batutils.tpu.iters import nested_get
dtu.any_to_datetime('2024-04-02 13:47:25') # datetime(2024, 4, 2, 13, 47, 25)
dtu.agostr(dtu.ago(days=5)) # '5 days'
int_eval('0x10') # 16
bool_eval('Yes') # True
nested_get({'a': {'b': [1, 2, 3]}}, ('a', 'b', -1)) # 3
Common imports
from batutils.structs import * pulls in the imports that nearly every file in
our projects needs:
from typing import * # for type annotations
import abc # interfaces (Abstract Base Classes)
import dataclasses # dataclass structs
import decimal # anything involving money
import enum # also used for struct creation
import logging # used pretty much everywhere
import re # used surprisingly frequently
import time # very commonly used
datetime itself is not included. Instead you get the date/time aliases from
batutils.dtu.structs.aliases:
Date = datetime.date
Time = datetime.time
Datetime = datetime.datetime
TimeDelta = datetime.timedelta
TzInfo = datetime.tzinfo
TimeZone = datetime.timezone
Plus a few of the most commonly used helpers from the type utils:
- the
Singletonmetaclass Empty,EmptyDictandif_empty- the
EnumExbase class for enums (adds thefrom_anyclass method)
So one line covers roughly 90% of the imports we need in any given file:
from batutils.structs import *
Changes from ccptools
The legacyapi submodule has been removed. See the changelog
for the full history.
Contributing and license
Issues and pull requests are welcome at github.com/doddi79/batutils. Released under the MIT License.
Metadata
Release files for batutils 2.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| batutils-2.2.1.tar.gz | 46.5 kB | Without provenance | Details for batutils-2.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| batutils-2.2.1-py3-none-any.whl | Python 3 | none | any | Details for batutils-2.2.1-py3-none-any.whl |
Total release size: 107.7 kB
Release files / batutils-2.2.1.tar.gz
| Download URL | batutils-2.2.1.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e31bb8ca4e14736f1042a7b0f799fcd417e1e4609517d2c6fa8a4d14c1780d65
|
|
BLAKE2b-256 checksum How to use checksums |
7ebc319acb84009f552cf1a8d515d54a43400932bba124bb987bf6807b2d0330
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / batutils-2.2.1-py3-none-any.whl
| Download URL | batutils-2.2.1-py3-none-any.whl |
|---|---|
| Size | 61.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a6afe997e9195aa08c56b50f6b186b79caf5db0d3e18c83a5405cb16f3be7245
|
|
BLAKE2b-256 checksum How to use checksums |
ee5b29bdb2137ae93e7166219a29dc7d3ca10fb8ce401099655a8ecf96ef7912
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for batutils 2.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.