Getting Started¶
Install The Module¶
This is a standard Python module and can be installed using pip as usual:
pip install camlistore
Connect To Camlistore¶
Before this library will be of any use you will need a Camlistore server running. See the Camlistore docs for more details.
Once you have a server running you can connect to it using
camlistore.connect(). For example, if you have your Camlistore
server running on localhost:
import camlistore
conn = camlistore.connect("http://localhost:3179/")
This function will contact the specified URL to make sure it looks like
a valid Camlistore server and discover some details about its configuration.
The conn return value is then a camlistore.Connection object,
configured and ready to access the server.
Try Writing A Blob!¶
To test if we’ve connected successfully, we can try some simple calls to write a blob and retrieve it again:
blobref = conn.blobs.put(camlistore.Blob("Hello, Camlistore!"))
hello_blob = conn.blobs.get(blobref)
print hello_blob.data
If things are working as expected, this should print out
Hello, Camlistore!, having successfully written that string into the store
and retrieved it again. You’re now ready to proceed to the following sections
to learn more about the blob store and search interfaces.
This program will fail if the connection is not configured properly. For example, it may fail if the Camlistore server requires authentication, since our example does not account for that.
Connection Interface Reference¶
-
camlistore.connect(base_url)¶ Create a connection to the Camlistore instance at the given base URL.
This function implements the Camlistore discovery protocol to recognize a server and automatically determine which features are available, ultimately instantiating and returning a
Connectionobject.For now we assume an unauthenticated connection, which is generally only possible when connecting via
localhost. In future this function will be extended with some options for configuring authentication.
-
class
camlistore.Connection(http_session=None, blob_root=None, search_root=None, sign_root=None)¶ Represents a logical connection to a camlistore server.
Most callers should not instantiate this directly, but should instead use
connect(), which implements the Camlistore server discovery protocol to auto-configure an instance of this class.Note that this does not imply a TCP or any other kind of socket connection, but merely some persistent state that will be used when making requests to the server. In particular, several consecutive requests via the same connection may be executed via a single keep-alive HTTP connection, reducing round-trip time.