$ pip install oxenai
import oxen oxen.clone("ox/SpanishToEnglish")
This will create a directory called
SpanishToEnglish in your current working directory and download the latest version of the repository.
Not all repositories are public. If you are trying to clone a private repository, you will need to configure auth before you can clone.
If you try to clone a repository you do not have access to, and you have not configured auth, you will see the following error:
ValueError: oxen authentication token not found, obtain one from your administrator and configure with: oxen config --auth <HOST> <TOKEN>
Obtain Auth Token
Before you can push to a remote repository, you must have permissions to do so. Permissions are handled through an
auth_token that is passed in with the request.
You can obtain an
auth_token by creating an account on Oxen.ai and going to your profile.
Set Auth Token
To set your auth token, you can either set it through the command line interface or directly in python.
from oxen.auth import config_auth config_auth("YOUR_AUTH_TOKEN")
This will write the auth token to a file in
~/.config/oxen/auth_config.toml for future use. If you set up your own oxen-server you can generate custom auth tokens there.
In order for Oxen to know who is committing and where to sync to by default, you must call config_user and pass in the name and email you would like to use in your commit messages.
from oxen.user import config_user config_user("YOUR NAME", "YOUR EMAIL")
This will save a file in
~/.config/oxen/user_config.toml that contains your user configuration.
If you are creating a new repository from scratch, you can initialize it with the init method.
We will be using a fictional repository called
CatsVsDogs for this example.
import oxen import os # Create an empty directory named CatsVsDogs directory = "CatsVsDogs" os.makedirs(directory) # Initialize the Oxen Repository repo = oxen.init(directory)
This will create a
.oxen directory to keep track of changes as you make them.
Load Existing Repository
Use the LocalRepo class to interact with a repository that has already been initialized.
from oxen import LocalRepo # Load the repostory from the CatsVsDogs directory repo = LocalRepo("CatsVsDogs") # Check the status of the repository print(repo.status())
Now let’s create a README.md file and add it to the local staging area. This will not commit the changes to the repository, but it will prepare them to be committed.
# ... continue from previous example # Create a README.md file filename = os.path.join(repo.path, "README.md") with open(filename, "w") as f: f.write("# Cats vs. Dogs\n\nWhich is it? We will be using machine learning to find out!") # Add the README.md file to the staging area repo.add(filename) # Confirm that the file has been staged print(repo.status())
Now that we have added the README.md file to the staging area, we can commit the changes to the repository.
# ... continue from previous example # Commit the changes to the repository repo.commit("Adding README.md")
Push To Remote
It’s one thing to version your data locally, but where the real power comes in is when you can share your data with others. Oxen repositories can be pushed to a remote repository hosted on Oxen Hub or your own oxen-server.
There are a few steps when pushing to a remote for the first time.
Before you can push to a remote repository, you must create it. This can be done with the create_repo method.
from oxen.remote_repo import create_repo # Create a remote repository remote_name = "MyNamespace/CatsVsDogs" create_repo(remote_name)
Point Local to Remote
Now that we have created the remote repository, we need to point our local repository to sync to it. This can be done with the set_remote method.
from oxen import LocalRepo # Load the local repository local_repo = LocalRepo("CatsVsDogs") # Point the local repository to the remote local_repo.set_remote(remote_name)
Now that we have created the remote repository and pointed our local repository to it, we can push our changes to the remote repository.
# Push the changes to the remote repository local_repo.push()
Full Push Example
The end to end workflow from scratch looks like this:
from oxen import LocalRepo from oxen.remote_repo import create_repo from oxen.auth import config_auth # 0. Load the local repository local_repo = LocalRepo("CatsVsDogs") # 1. Configure Authentication config_auth("YOUR_AUTH_TOKEN") # 2. Create a remote repository remote_name = "MyNamespace/CatsVsDogs" create_repo(remote_name) # 3. Point the local repository to the remote local_repo.set_remote(remote_name) # 4. Push the changes to the remote repository local_repo.push()
Now that we have pushed our changes to the remote repository, we can pull them down to another machine.
import oxen import os repo_path = "CatsVsDogs" if os.path.exists(repo_path): # if you already have a local copy of the repository, you can load it repo = oxen.LocalRepo(repo_path) else: # if you don't have a local copy of the repository, you can clone it repo = oxen.clone("ox/CatsVsDogs") # Pull the latest changes from the remote repository repo.pull()
Branching is a powerful feature of Oxen that allows you to create a named version of your data without affecting the original version. This is useful when you want to experiment with your changes affecting the original version.
To create a new branch, use the LocalRepo.checkout method.
from oxen import LocalRepo repo = LocalRepo("CatsVsDogs") repo.checkout("add-dogs", create=True)
This both creates the branch and checks it out (the command line equivalent of
oxen checkout -b add-dogs).
To list all of the branches in a repository, use the LocalRepo.branches method.
from oxen import LocalRepo repo = LocalRepo("CatsVsDogs") print(repo.branches())
[Branch(name=add-dogs, commit_id=3168391af834ac18), Branch(name=main, commit_id=3168391af834ac18)]
As you can see there should be a
main branch and a
add-dogs branch, each tied to a commit id. The commit ids will be the same at this point, because the branches have not diverged in content.
Now that you have learned the basics of Oxen, the rest of the workflow is very similar to git. You can dive deeper into the API Documentation to learn more about the methods available to you.