Package: metabaiji-pod
This is an active fork ofbaiji-pod, Body Labs’ asset
cache for S3 usingbaiji.The fork’s goals are modest:Keep the library working in current versions of Python and other
tools.Make bug fixes.Provide API stability and backward compatibility with the upstream
version.Respond to community contributions.It’s used by related forks such aslace.InstallationInstall the fork:pipinstallmetabaiji-podAnd import it just like the upstream library:frombaiji.podimportAssetCachefrombaiji.podimportConfigfrombaiji.podimportVersionedCacheOverviewVersioned-tracked assets and a low-level asset cache for Amazon S3,
usingbaiji.FeaturesVersioned cache for version-tracked assetsCreates a new file each time it changesUsing a checked-in manifest, each revision of the code is pinned
to a given version of the fileConvenient CLI for pushing updatesLow-level asset cache, for any S3 pathAssets are stored locally, and revalidated after a timeoutPrefill tool populates the caches with a list of needed assetsSupports Python 2.7Supports OS X, Linux, and WindowsA few dev features only work on OS XTested and production-hardenedThe versioned cacheThe versioned cache provides access to a repository of files. The
changes to those files are tracked and identified with to a semver-like
version number.To use the versioned cache, you need a copy of a manifest file, which
lists all the versioned paths and the latest version of each one. When
you request a file from the cache, it consults this manifest file to
determine the correct version. The versioned cache delegates loading to
the underlying asset cache.The versioned cache was designed for compute assets: chunks of data
which are used in code. When the manifest is checked in with the code,
it pins the version of each asset. If the asset is subsequently updated,
that revision of the code will continue to get the version it’s
expecting.The bucket containing the versioned assets is intended to be immutable.
Nothing there should ever be changed or deleted. Only new versions
added.The manifest looks like this:{"/foo/bar.csv":"1.2.5","/foo/bar.json":"0.1.6"}To load a versioned asset:import json
from baiji.pod import AssetCache
from baiji.pod import Config
from baiji.pod import VersionedCache

config = Config()
# Improve performance by assuming the bucket is immutable.
config.IMMUTABLE_BUCKETS = ['my-versioned-assets']

vc = VersionedCache(
    cache=AssetCache(config),
    manifest_path='versioned_assets.json',
    bucket='my-versioned-assets')

with open(vc('/foo/bar.json'), 'r') as f:
    data = json.load(f)Or, with`baiji-serialization<https://github.com/bodylabs/baiji-serialization>`__:from baiji.serialization import json
data = json.load(vc('s3://example-bucket/example.json'))To add a new versioned path, or update an existing one, use thevccommand-line tool:vc add /foo/bar.csv ~/Desktop/bar.csv
vc update --major /foo/bar.csv ~/Desktop/new_bar.csv
vc update --minor /foo/bar.csv ~/Desktop/new_bar.csv
vc update --patch /foo/bar.csv ~/Desktop/new_bar.csvA VersionedCache object is specific to a manifest file and a bucket.Though the version number uses semver-like semantics, the cache ignores
version semantics. The manifest pins an exact version number.The asset cacheThe asset cache works at a lower level of abstraction. It holds local
copies of arbitrary S3 assets. Calling thecache()function with an
S3 path ensures that the file is available locally, and then returns a
valid, local path.On a cache miss, the file is downloaded to the cache and then its local
path is returned. Subsequent calls will return the same local path.
After a timeout, which defaults to one day, the validity of the local
file is checked by comparing a local MD5 hash with the remote etag. This
check is repeated once per day.To gain a performance boost, you can configure immutable buckets, whose
contents are never revalidated after download. The versioned cache uses
this feature.import json
from baiji.pod import AssetCache

cache = AssetCache.create_default()

with open(cache('s3://example-bucket/example.json'), 'r') as f:
    data = json.load(f)Or, with`baiji-serialization<https://github.com/bodylabs/baiji-serialization>`__:from baiji.serialization import json
data = json.load(cache('s3://example-bucket/example.json'))It is safe to callcachemultiple times:cache(cache('path'))will behave correctly.TipsWhen you’re developing, you often want to try out variations on a file
before committing to a particular one. Rather than incrementing the
patch level over and over, you can setmanifest.jsonto include an
absolute path:"/foo/bar.csv": "/Users/me/Desktop/foo.obj",This can be either a local or an s3 path; use local if you’re iterating
by yourself, and s3 to iterate with other developers or in CI.Developmentpipinstall-rrequirements_dev.txtrakeunittestrakelintTODOAdd vc config to configExplain or clean up the weird default_bucket config logic in
prefill_runner. e.g. This logic is so that we can have a
customized script in core that doesn’t require these arguments.Use config without subclassing. Pass overries to initConfigure using an importable config path instead of injecting. Or,
possibly, allow ~/.aws/baiji_config to change defaults.Rework baiji.pod.util.reachability and perhaps
baiji.util.reachability as well.Restore CDN publish functionality in coreAvoid using actual versioned assets. Perhaps write some (smaller!)
files to a test bucket and use those?Remove suffixes support in vc.uri, used only for CDNPublisherMove yaml.dump and json.* to baiji. Possibly do atry: from baiji.serialization.json import load, dump; except ImportError: defload(...Or at least have a comment to the effect of “don’t use this, use
baiji.serialization.json”Use consistent argparse pattern in the runners.I think it would be better if the CacheFile didn’t need to know about
the AssetCache, to avoid this bi-directional dependency. It’s only
required in the constructor, but that could live on the AssetCache,
e.g. create_cache_file(path, bucket=None).ContributeIssue Tracker:https://github.com/metabolize/baiji-pod/issuesSource Code:https://github.com/metabolize/baiji-podPull requests welcome!SupportIf you are having issues, please let us know.Acknowledgementsbaiji-pod was developed at Body Labs, primarily byAlex
WeissandPaul
Melnikow.LicenseThe project is licensed under the Apache license, version 2.0.