Debian Codegraph @

README.md

raw
1 # conda-package-streaming
2
3 [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/conda/conda-package-streaming/main.svg)](https://results.pre-commit.ci/latest/github/conda/conda-package-streaming/main)
4
5 An efficient library to read from new and old format .conda and .tar.bz2 conda
6 packages.
7
8 Download conda metadata from packages without transferring entire file. Get
9 metadata from local `.tar.bz2` packages without reading entire files.
10
11 Uses enhanced pip `lazy_wheel` to fetch a file out of `.conda` with no more than
12 3 range requests, but usually 2.
13
14 Uses `tar = tarfile.open(fileobj=...)` to stream remote `.tar.bz2`. Closes the
15 HTTP request once desired files have been seen.
16
17 # Quickstart
18
19 The basic API yields (tarfile, member) tuples from conda files as tarfile is
20 needed to extract member. Note the `.tar.bz2` format yields all members, not
21 just `info/`, from `stream_conda_info` / `stream_conda_component`, while the
22 `.conda` format yields members from the requested inner archive — allowing the
23 caller to decide when to stop reading.
24
25 From a url,
26 ```python
27 from conda_package_streaming.url import stream_conda_info
28
29 # url = (ends with .conda or .tar.bz2)
30 for tar, member in stream_conda_info(url):
31 if member.name == "info/index.json":
32 index_json = json.load(tar.extractfile(member))
33 break
34 ```
35
36 From s3,
37 ```python
38 client = boto3.client("s3")
39 from conda_package_streaming.s3 import stream_conda_info
40
41 # key = (ends with .conda or .tar.bz2)
42 for tar, member in stream_conda_info(client, bucket, key):
43 if member.name == "info/index.json":
44 index_json = json.load(tar.extractfile(member))
45 break
46 ```
47
48 From a filename,
49 ```python
50 from conda_package_streaming import package_streaming
51
52 # filename = (ends with .conda or .tar.bz2)
53 for tar, member in package_streaming.stream_conda_info(filename):
54 if member.name == "info/index.json":
55 index_json = json.load(tar.extractfile(member))
56 break
57 ```
58
59 From a file-like object,
60 ```python
61 from contextlib import closing
62
63 from conda_package_streaming.url import conda_reader_for_url
64 from conda_package_streaming.package_streaming import stream_conda_component
65
66 filename, conda = conda_reader_for_url(url)
67
68 # file object must be seekable for `.conda` format, but merely readable for `.tar.bz2`
69 with closing(conda):
70 for tar, member in stream_conda_component(filename, conda, component="info"):
71 if member.name == "info/index.json":
72 index_json = json.load(tar.extractfile(member))
73 break
74 ```
75
76 If you need the entire package, download it first and use the file-based APIs.
77 The URL-based APIs are more efficient if you only need to access package
78 metadata.
79
80 # Package goals
81
82 * Extract conda packages (both formats)
83 * Easy to install from pypi or conda
84 * Do the least amount of I/O possible (no temporary files, transfer partial packages)
85 * Open files from the network / standard HTTP / s3
86
87 * Continue using conda-package-handling to create .conda packages
88
89 # Generating documentation
90
91 Uses markdown, furo theme. Requires newer mdit-py-plugins.
92
93 `pip install conda-package-streaming[docs]`
94
95 One time:
96 `sphinx-apidoc -o docs .`