๐ Python
Learn how to get started with the oxenai python package.
Install
Clone Repository
Clone a repository from the Oxen Hub or a your own oxen-server. Detailed documentation for the clone method can be found in the API Documentation.
This will create a directory called SpanishToEnglish
in your current working directory and download the latest version of the repository.
Private Repositories
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:
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.
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.
Setup User
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.
This will save a file in ~/.config/oxen/user_config.toml
that contains your user configuration.
Initialize Local Repository
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.
This will create a .oxen
directory to keep track of changes as you make them.
Load Existing Repository
Use the repo class to interact with a repository that has already been initialized.
Add Files
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.
Commit Changes
Now that we have added the README.md file to the staging area, we can commit the changes to the repository.
Diff Changes
Oxen.ai has powerful diff tools built in that allow you to see the changes to files between commits, branches, and more.
To learn more about diffs checkout the diff documentation or the Python API Documentation.
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.
Create Remote
Before you can push to a remote repository, you must create it. This can be done with the create_repo method.
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.
Push Changes
Now that we have created the remote repository and pointed our local repository to it, we can push our changes to the remote repository.
Full Push Example
The end to end workflow from scratch looks like this:
Pull Data
Now that we have pushed our changes to the remote repository, we can pull them down to another machine.
Branching
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.
Create Branch
To create a new branch, use the Repo.checkout method.
This both creates the branch and checks it out (the command line equivalent of oxen checkout -b add-dogs
).
List Branches
To list all of the branches in a repository, use the Repo.branches method.
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.
Next Steps
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.