### Install Go Dependencies Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Installs the required Go dependencies for the project using the go mod tidy command. This ensures all necessary packages are available. ```go go mod tidy ``` -------------------------------- ### Clone Repository Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Clones the wme-sdk-go repository and navigates into the project directory. This is the initial step to get the example code. ```sh git clone https://github.com/wikimedia-enterprise/wme-sdk-go.git cd wme-sdk-go ``` -------------------------------- ### Login Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Get access token and refresh token by sending in username and password. ```APIDOC ## POST /v1/login ### Description Get access token and refresh token by sending in username and password. ### Method POST ### Endpoint https://auth.enterprise.wikimedia.com/v1/login ### Parameters #### Request Body - **username** (string) - Required - The user's username. - **password** (string) - Required - The user's password. ### Request Example ```json { "username" : "usernamexyz", "password": "passwordxyz" } ``` ### Response #### Success Response (200) - **id_token** (string) - The user's ID token. - **access_token** (string) - The access token for API requests. - **refresh_token** (string) - The refresh token to obtain new access tokens. - **expires_in** (integer) - The expiration time of the access token in seconds. #### Response Example ```json { "id_token": "abc....", "access_token": "abc...", "refresh_token": "abc..", "expires_in": 86400 } ``` **Note**: The access token is required to use any of our data and metadata APIs. An access token is valid for 24 hours. You may generate a fresh access token using the refresh token. For Realtime Streaming API, the connection is long-lived and will not be disconnected because the `access_token` expires after 24 hours. ``` -------------------------------- ### Token Refresh Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Get a new access token by sending in the username and refresh token. ```APIDOC ## POST /v1/token-refresh ### Description Get a new access token by sending in the username and refresh token. A valid user can have up to 90 access tokens at any time. ### Method POST ### Endpoint https://auth.enterprise.wikimedia.com/v1/token-refresh ### Parameters #### Request Body - **username** (string) - Required - The user's username. - **refresh_token** (string) - Required - The user's refresh token. ### Request Example ```json { "username" : "usernamexyz", "refresh_token": "abc.." } ``` ### Response #### Success Response (200) - **id_token** (string) - The user's ID token. - **access_token** (string) - The new access token. - **expires_in** (integer) - The expiration time of the new access token in seconds. #### Response Example ```json { "id_token": "xyz..", "access_token": "xyz...", "expires_in": 86400 } ``` ``` -------------------------------- ### Install wme-sdk-go Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/README.md This command installs the Wikimedia Enterprise SDK for Go using the go get command. Ensure you have Go installed and configured in your environment. ```bash go get github.com/wikimedia-enterprise/wme-sdk-go ``` -------------------------------- ### Run Auth Helper Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Executes the main Go application which demonstrates the authentication helper. The application logs in, obtains an access token, and sets up a background goroutine for automatic token refreshing. ```go cd example/auth go run main.go ``` -------------------------------- ### Get All SC Snapshot Metadata (Bash) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Fetches metadata for all available Structured-Contents snapshots. This is a simple POST request to the snapshots endpoint. ```bash POST https://api.enterprise.wikimedia.com/v2/snapshots/structured-contents ``` -------------------------------- ### Login API Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Obtain an access token and refresh token by providing a username and password. The access token is crucial for accessing data APIs and is valid for 24 hours. A refresh token can be used to generate a new access token. ```Bash POST https://auth.enterprise.wikimedia.com/v1/login with request parameter: { "username" : "usernamexyz", "password": "passwordxyz" } ``` ```JSON { "id_token": "abc....", "access_token": "abc...", "refresh_token": "abc..", "expires_in": 86400 } ``` -------------------------------- ### Set Environment Variables Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Sets up the necessary environment variables for username and password, typically stored in a .env file. These credentials are used for authentication. ```bash export WME_USERNAME="...your username..."; export WME_PASSWORD="...your password..." ``` -------------------------------- ### Forgot Password API Examples Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Initiate a password reset by sending a username to the forgot-password endpoint. Subsequently, confirm the new password using the provided confirmation code and username. ```Bash POST https://auth.enterprise.wikimedia.com/v1/forgot-password with request parameter: { "username": "abc.." } ``` ```Bash POST https://auth.enterprise.wikimedia.com/v1/forgot-password-confirm with request parameter: { "username": "abc..", "password": "new_password", "confirmation_code" : "123456" } ``` -------------------------------- ### Token Refresh API Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Generate a new access token using an existing username and refresh token. Users can possess up to 90 access tokens concurrently. This method is essential for maintaining authentication without requiring re-entry of credentials. ```Bash POST https://auth.enterprise.wikimedia.com/v1/token-refresh with request parameter: { "username" : "usernamexyz", "refresh_token": "abc.." } ``` ```JSON { "id_token": "xyz..", "access_token": "xyz...", "expires_in": 86400 } ``` -------------------------------- ### Forgot Password Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Allows you to set a new password by sending a code to your associated email. ```APIDOC ## POST /v1/forgot-password ### Description Allows you to initiate the password reset process by sending a confirmation code to the user's associated email. ### Method POST ### Endpoint https://auth.enterprise.wikimedia.com/v1/forgot-password ### Parameters #### Request Body - **username** (string) - Required - The user's username. ### Request Example ```json { "username": "abc.." } ``` ## POST /v1/forgot-password-confirm ### Description Completes the password reset process by providing the confirmation code and the new password. ### Method POST ### Endpoint https://auth.enterprise.wikimedia.com/v1/forgot-password-confirm ### Parameters #### Request Body - **username** (string) - Required - The user's username. - **password** (string) - Required - The new password for the user. - **confirmation_code** (string) - Required - The confirmation code sent to the user's email. ### Request Example ```json { "username": "abc..", "password": "new_password", "confirmation_code" : "123456" } ``` ``` -------------------------------- ### Fetch Articles by Name, Project, and Fields (Bash) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-contents/README.md Retrieves pre-parsed articles by name from a specific project and language, with selected fields returned. This example uses a POST request to the API, including filters for the project and a list of desired fields in the JSON payload. ```bash POST https://api.enterprise.wikimedia.com/v2/structured-contents/Montreal { "limit": 1, "filters": [ { "field": "is_part_of.identifier", "value": "enwiki" } ], "fields": ["abstract", "article_sections", "infoboxes"] } ``` -------------------------------- ### Get Metadata of All Available SC Snapshots Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Retrieves metadata for all available structured-content snapshots. This is a POST request to the base snapshots endpoint. ```APIDOC ## POST /v2/snapshots/structured-contents ### Description Retrieves metadata for all available structured-content snapshots. ### Method POST ### Endpoint https://api.enterprise.wikimedia.com/v2/snapshots/structured-contents ### Parameters #### Query Parameters None #### Request Body Optional. Can include filters to refine the results. ```json { "filters": [ { "field": "in_language.identifier", "value": "en" } ] } ``` ### Request Example ```json { "filters": [ { "field": "in_language.identifier", "value": "en" } ] } ``` ### Response #### Success Response (200) Metadata of available SC snapshots. #### Response Example ```json { "example": "[Response content for all snapshots]" } ``` ``` -------------------------------- ### Download Snapshot (Full) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/snapshots/README.md Initiates the download of an entire snapshot file. This GET request retrieves the complete snapshot data from the specified URL. ```bash GET https://api.enterprise.wikimedia.com/v2/snapshots/afwikibooks_namespace_0/download ``` -------------------------------- ### Change Password API Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Update an existing password by providing the access token, the previous password, and the desired new password. This is used when the user remembers their current password but wishes to change it. ```Bash POST https://auth.enterprise.wikimedia.com/v1/change-password with request parameter: { "access_token": "xyz...", "previous_password": "password1", "proposed_password": "password2" } ``` -------------------------------- ### Change Password Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Update your current password. ```APIDOC ## POST /v1/change-password ### Description Updates the user's password when the current password is known. ### Method POST ### Endpoint https://auth.enterprise.wikimedia.com/v1/change-password ### Parameters #### Request Body - **access_token** (string) - Required - The user's valid access token. - **previous_password** (string) - Required - The user's current password. - **proposed_password** (string) - Required - The new password to set. ### Request Example ```json { "access_token": "xyz...", "previous_password": "password1", "proposed_password": "password2" } ``` ``` -------------------------------- ### Download Single SC Snapshot by Identifier (Bash) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Downloads a specific Structured-Contents snapshot using its identifier. This is a GET request to the download endpoint for the snapshot. ```bash GET https://api.enterprise.wikimedia.com/v2/snapshots/structured-contents/enwiki_namespace_0/download ``` -------------------------------- ### Get Available Namespaces using Go SDK Source: https://context7.com/wikimedia-enterprise/wme-sdk-go/llms.txt Lists all available Wikipedia namespaces that can be queried through the wme-sdk-go. It involves authentication and API client setup. The code then retrieves namespaces and prints their identifiers and names. ```go package main import ( "context" "log" "os" "github.com/wikimedia-enterprise/wme-sdk-go/pkg/api" "github.com/wikimedia-enterprise/wme-sdk-go/pkg/auth" ) func main() { ctx := context.Background() authClient := auth.NewClient() loginResponse, err := authClient.Login(ctx, &auth.LoginRequest{ Username: os.Getenv("WME_USERNAME"), Password: os.Getenv("WME_PASSWORD"), }) if err != nil { log.Fatalf("Login failed: %v", err) } defer authClient.RevokeToken(ctx, &auth.RevokeTokenRequest{ RefreshToken: loginResponse.RefreshToken, }) apiClient := api.NewClient() apiClient.SetAccessToken(loginResponse.AccessToken) namespaces, err := apiClient.GetNamespaces(ctx, nil) if err != nil { log.Fatalf("Failed to get namespaces: %v", err) } for _, namespace := range namespaces { log.Printf("Namespace %d: %s", namespace.Identifier, namespace.Name) } } ``` -------------------------------- ### Get All Project Codes (Metadata API) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md Retrieves all available project codes (types) from the Metadata API. This endpoint can be used without any parameters to fetch a comprehensive list. The response is a JSON array of project code objects. ```bash GET https://api.enterprise.wikimedia.com/v2/codes ``` -------------------------------- ### Token Revoke API Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Invalidate all active access tokens for a user by providing their refresh token. This action immediately terminates all current sessions and requires the user to re-authenticate. ```Bash POST https://auth.enterprise.wikimedia.com/v1/token-revoke with request parameter: { "refresh_token": "abc.." } ``` -------------------------------- ### Token Revoke Example Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/login/README.md Invalidates all access tokens for a user by sending in the refresh token. ```APIDOC ## POST /v1/token-revoke ### Description Invalidates all the access tokens for a user, by sending in refresh_token. ### Method POST ### Endpoint https://auth.enterprise.wikimedia.com/v1/token-revoke ### Parameters #### Request Body - **refresh_token** (string) - Required - The user's refresh token. ### Request Example ```json { "refresh_token": "abc.." } ``` ``` -------------------------------- ### GET /projects Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md Retrieves metadata for all supported Wikimedia projects. This endpoint supports filtering by various criteria and allows for selecting specific fields in the response. It can also be used to query information for a single project. ```APIDOC ## GET /projects ### Description Retrieves metadata for all supported Wikimedia projects. Supports filtering and field selection. Allows to query single project. ### Method GET ### Endpoint https://api.enterprise.wikimedia.com/v2/projects ### Parameters #### Query Parameters - **filter** (string) - Optional - Allows filtering the results based on specified criteria. - **fields** (string) - Optional - Specifies which fields to include in the response. ### Request Example ```bash GET https://api.enterprise.wikimedia.com/v2/projects?filter=language:en&fields=name,url ``` ### Response #### Success Response (200) - **name** (string) - The name of the project. - **identifier** (string) - A unique identifier for the project. - **url** (string) - The base URL for the project. - **code** (string) - A short code representing the project type (e.g., 'wiki', 'wikibooks'). - **in_language** (object) - Information about the language of the project. - **identifier** (string) - The language code (e.g., 'en', 'cv'). #### Response Example ```json [ { "name": "Wikipedia", "identifier": "enwiki", "url": "https://en.wikipedia.org", "code": "wiki", "in_language": { "identifier": "en" } } ] ``` ``` -------------------------------- ### Download a Single SC Snapshot Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Downloads a specific structured-content snapshot using its identifier. ```APIDOC ## GET /v2/snapshots/structured-contents/{identifier}/download ### Description Downloads a single structured-content snapshot identified by its unique identifier. ### Method GET ### Endpoint https://api.enterprise.wikimedia.org/v2/snapshots/structured-contents/enwiki_namespace_0/download ### Parameters #### Path Parameters - **identifier** (string) - Required - The unique identifier of the SC snapshot to download (e.g., `enwiki_namespace_0`). #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) The structured-content snapshot file. #### Response Example ```json { "example": "[Snapshot file content]" } ``` ``` -------------------------------- ### Get Snapshot Headers Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/snapshots/README.md Fetches header information for a snapshot download URL. This is useful for determining file size and other transfer-related details before initiating a full download. It uses the HEAD HTTP method. ```bash HEAD https://api.enterprise.wikimedia.com/v2/snapshots/afwikibooks_namespace_0/download ``` -------------------------------- ### Initialize Auth Client and Helper in Go Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Initializes the authentication client and helper in Go. The helper manages token state, including automatic refreshing and re-login as needed for API calls. ```go authClient := auth.NewClient() helper, err := auth.NewHelper(authClient) if err != nil { log.Fatalln(err) } ``` -------------------------------- ### Make Authenticated API Call in Go Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Demonstrates making an authenticated API call using the obtained access token. It initializes an API client, sets the token, and calls GetArticles, handling potential errors and logging results. ```go tkn, err := helper.GetAccessToken() if err != nil { log.Printf("failed to get access token for request %d: %v", req, err) return } clt := api.NewClient() clt.SetAccessToken(tkn) arq := &api.Request{ Fields: []string{"name", "abstract", "url", "version"}, Filters: []*api.Filter{ { Field: "in_language.identifier", Value: "en", }, }, } res, err := clt.GetArticles(ctx, "Montreal", arq) if err != nil { log.Printf("failed to get articles for request %d: %v", req, err) return } log.Printf("request %d: %d articles found", req, len(res)) ``` -------------------------------- ### GET /languages Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md Retrieves all supported languages with their metadata. This endpoint supports filtering and field selection. ```APIDOC ## GET /languages ### Description Retrieves all supported languages with their metadata. Supports filtering and field selection. ### Method GET ### Endpoint https://api.enterprise.wikimedia.com/v2/languages ### Parameters #### Query Parameters - **filter** (string) - Optional - Allows filtering the results based on specified criteria. - **fields** (string) - Optional - Allows selecting specific fields to be returned in the response. ### Request Example ```json { "example": "GET https://api.enterprise.wikimedia.com/v2/languages?filter=direction:ltr&fields=identifier,name" } ``` ### Response #### Success Response (200) - **identifier** (string) - The unique identifier for the language. - **name** (string) - The common name of the language. - **alternate_name** (string) - An alternative name for the language. - **direction** (string) - The text directionality of the language (ltr or rtl). #### Response Example ```json [ { "identifier": "cv", "name": "Chuvash", "alternate_name": "чӑвашла", "direction": "ltr" }, { "identifier": "id", "name": "Indonesian", "alternate_name": "Bahasa Indonesia", "direction": "ltr" } ] ``` ``` -------------------------------- ### Get Metadata of a Single SC Snapshot Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Retrieves metadata for a specific structured-content snapshot using its identifier. ```APIDOC ## POST /v2/snapshots/structured-contents/{identifier} ### Description Retrieves metadata for a single structured-content snapshot identified by its unique identifier. ### Method POST ### Endpoint https://api.enterprise.wikimedia.org/v2/snapshots/structured-contents/enwiki_namespace_0 ### Parameters #### Path Parameters - **identifier** (string) - Required - The unique identifier of the SC snapshot (e.g., `enwiki_namespace_0`). #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Metadata of the specified SC snapshot. #### Response Example ```json { "example": "[Response content for a single snapshot]" } ``` ``` -------------------------------- ### GET /v2/namespaces Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md Retrieves information about all supported namespaces. This endpoint supports filtering and field selection, and can also be used to query for a single namespace. ```APIDOC ## GET /v2/namespaces ### Description Retrieves metadata for all supported namespaces. This endpoint allows filtering by namespace properties and selecting specific fields for the response. It can also be used to fetch details for a single namespace. ### Method GET ### Endpoint https://api.enterprise.wikimedia.com/v2/namespaces ### Parameters #### Query Parameters - **filter** (string) - Optional - Allows filtering namespaces based on certain criteria. - **fields** (string) - Optional - Specifies which fields to include in the response (e.g., "name,identifier"). ### Request Example ```bash GET https://api.enterprise.wikimedia.com/v2/namespaces?filter=name:Category&fields=name,description ``` ### Response #### Success Response (200) - **name** (string) - The name of the namespace. - **identifier** (integer) - The unique identifier for the namespace. - **description** (string) - A brief description of the namespace's purpose. #### Response Example ```json [ { "name": "Category", "identifier": 14, "description": "Categories are intended to group together pages on similar subjects. They are implemented by a MediaWiki feature that adds any page with a text like [[Category:XYZ]] in its wiki markup to the automated listing that is the category with name XYZ. Categories help readers to find, and navigate around, a subject area, to see pages sorted by title, and to thus find article relationships." } ] ``` ``` -------------------------------- ### Get Metadata of All Available SC Snapshots in English Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Retrieves metadata for all available structured-content snapshots specifically for the English language. This uses a filter in the request body. ```APIDOC ## POST /v2/snapshots/structured-contents (Filtered for English) ### Description Retrieves metadata for all available structured-content snapshots in English. ### Method POST ### Endpoint https://api.enterprise.wikimedia.com/v2/snapshots/structured-contents ### Parameters #### Query Parameters None #### Request Body Required. Filters the results to include only snapshots in English. ```json { "filters": [ { "field": "in_language.identifier", "value": "en" } ] } ``` ### Request Example ```json { "filters": [ { "field": "in_language.identifier", "value": "en" } ] } ``` ### Response #### Success Response (200) Metadata of available SC snapshots in English. #### Response Example ```json { "example": "[Response content for English snapshots]" } ``` ``` -------------------------------- ### Get Specific Language Metadata Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md Retrieves metadata for a specific language using its identifier. This includes the language's name, alternate name, and text direction. ```APIDOC ## GET /v2/languages/{identifier} ### Description Retrieves metadata for a specific language identified by its unique identifier. ### Method GET ### Endpoint /v2/languages/{identifier} ### Parameters #### Path Parameters - **identifier** (string) - Required - The unique identifier of the language (e.g., 'fr' for French). #### Query Parameters None #### Request Body None ### Request Example ```bash GET https://api.enterprise.wikimedia.com/v2/languages/fr ``` ### Response #### Success Response (200) - **identifier** (string) - The unique identifier for the language. - **name** (string) - The common name of the language. - **alternate_name** (string) - An alternative name for the language. - **direction** (string) - The text direction ('ltr' for left-to-right, 'rtl' for right-to-left). #### Response Example ```json { "identifier": "fr", "name": "French", "alternate_name": "français", "direction": "ltr" } ``` ``` -------------------------------- ### Get Single SC Snapshot Metadata by Identifier (Bash) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Retrieves metadata for a single Structured-Contents snapshot using its unique identifier. The identifier is appended to the API endpoint. ```bash POST https://api.enterprise.wikimedia.com/v2/snapshots/structured-contents/enwiki_namespace_0 ``` -------------------------------- ### Get SC Snapshot Metadata Filtered by Language (JSON/Bash) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/structured-content-snapshot/README.md Fetches metadata for Structured-Contents snapshots, filtered by a specific language. The request body includes a JSON filter for the desired language identifier. ```bash POST https://api.enterprise.wikimedia.com/v2/snapshots/structured-contents ``` ```json { "filters": [ { "field": "in_language.identifier", "value": "en" } ] } ``` -------------------------------- ### Clear Authentication State in Go Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/auth/README.md Clears the authentication state, including revoking the token and removing state from storage when finished with WME APIs. This is important for security and proper cleanup. ```go if err := helper.ClearState(); err != nil { log.Printf("failed to clear state: %v", err) } ``` -------------------------------- ### Download and Process Batch with Callback in Go Source: https://context7.com/wikimedia-enterprise/wme-sdk-go/llms.txt Downloads a specific hourly batch and processes its articles using a callback function. Requires authentication. The callback logs the name and modification date of each processed article. Logs the total count of updated articles. ```Go package main import ( "context" "log" "os" "time" "github.com/wikimedia-enterprise/wme-sdk-go/pkg/api" "github.com/wikimedia-enterprise/wme-sdk-go/pkg/auth" ) func main() { ctx := context.Background() authClient := auth.NewClient() loginResponse, err := authClient.Login(ctx, &auth.LoginRequest{ Username: os.Getenv("WME_USERNAME"), Password: os.Getenv("WME_PASSWORD"), }) if err != nil { log.Fatalf("Login failed: %v", err) } defer authClient.RevokeToken(ctx, &auth.RevokeTokenRequest{ RefreshToken: loginResponse.RefreshToken, }) apiClient := api.NewClient() apiClient.SetAccessToken(loginResponse.AccessToken) batchDate := time.Date(2025, 7, 16, 5, 0, 0, 0, time.UTC) batchID := "enwiki_namespace_0" articleCount := 0 callback := func(article *api.Article) error { articleCount++ log.Printf("Processing article: %s (modified: %v)", article.Name, article.DateModified) return nil } err = apiClient.ReadBatch(ctx, &batchDate, batchID, callback) if err != nil { log.Fatalf("Failed to read batch: %v", err) } log.Printf("Processed %d updated articles", articleCount) } ``` -------------------------------- ### List Wikimedia Projects and Languages (Go) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md This Go code snippet demonstrates how to define and structure data for various Wikimedia projects and their corresponding languages. It includes details like project name, identifier, URL, code, and language identifier. ```go type WikimediaProject struct { Name string `json:"name"` Identifier string `json:"identifier"` URL string `json:"url"` Code string `json:"code"` InLanguage struct { Identifier string `json:"identifier"` } `json:"in_language"` } var projects = []WikimediaProject{ { Name: "Haitian Creole Wikipedia", Identifier: "hawiki", URL: "https://ha.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "ha"}, }, { Name: "Haitian Creole Wiktionary", Identifier: "hawiktionary", URL: "https://ha.wiktionary.org", Code: "wiktionary", InLanguage: struct{ Identifier string }{Identifier: "ha"}, }, { Name: "Italian Wikipedia", Identifier: "itwiki", URL: "https://it.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wiktionary", Identifier: "itwiktionary", URL: "https://it.wiktionary.org", Code: "wiktionary", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wikibooks", Identifier: "itwikibooks", URL: "https://it.wikibooks.org", Code: "wikibooks", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wikinews", Identifier: "itwikinews", URL: "https://it.wikinews.org", Code: "wikinews", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wikiquote", Identifier: "itwikiquote", URL: "https://it.wikiquote.org", Code: "wikiquote", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wikisource", Identifier: "itwikisource", URL: "https://it.wikisource.org", Code: "wikisource", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wikiversity", Identifier: "itwikiversity", URL: "https://it.wikiversity.org", Code: "wikiversity", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Italian Wikivoyage", Identifier: "itwikivoyage", URL: "https://it.wikivoyage.org", Code: "wikivoyage", InLanguage: struct{ Identifier string }{Identifier: "it"}, }, { Name: "Lithuanian Wikipedia", Identifier: "ltwiki", URL: "https://lt.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "lt"}, }, { Name: "Lithuanian Wiktionary", Identifier: "ltwiktionary", URL: "https://lt.wiktionary.org", Code: "wiktionary", InLanguage: struct{ Identifier string }{Identifier: "lt"}, }, { Name: "Lithuanian Wikibooks", Identifier: "ltwikibooks", URL: "https://lt.wikibooks.org", Code: "wikibooks", InLanguage: struct{ Identifier string }{Identifier: "lt"}, }, { Name: "Lithuanian Wikiquote", Identifier: "ltwikiquote", URL: "https://lt.wikiquote.org", Code: "wikiquote", InLanguage: struct{ Identifier string }{Identifier: "lt"}, }, { Name: "Lithuanian Wikisource", Identifier: "ltwikisource", URL: "https://lt.wikisource.org", Code: "wikisource", InLanguage: struct{ Identifier string }{Identifier: "lt"}, }, { Name: "Tamil Wikipedia", Identifier: "tnwiki", URL: "https://tn.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "tn"}, }, { Name: "Tamil Wiktionary", Identifier: "tnwiktionary", URL: "https://tn.wiktionary.org", Code: "wiktionary", InLanguage: struct{ Identifier string }{Identifier: "tn"}, }, { Name: "Amharic Wikipedia", Identifier: "amwiki", URL: "https://am.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "am"}, }, { Name: "Amharic Wiktionary", Identifier: "amwiktionary", URL: "https://am.wiktionary.org", Code: "wiktionary", InLanguage: struct{ Identifier string }{Identifier: "am"}, }, { Name: "Amharic Wikiquote", Identifier: "amwikiquote", URL: "https://am.wikiquote.org", Code: "wikiquote", InLanguage: struct{ Identifier string }{Identifier: "am"}, }, { Name: "Buginese Wikipedia", Identifier: "bugwiki", URL: "https://bug.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "bug"}, }, { Name: "Chuvash Wikipedia", Identifier: "chwiki", URL: "https://ch.wikipedia.org", Code: "wiki", InLanguage: struct{ Identifier string }{Identifier: "ch"}, }, { Name: "Chuvash Wiktionary", Identifier: "chwiktionary", URL: "https://ch.wiktionary.org", Code: "wiktionary", InLanguage: struct{ Identifier string }{Identifier: "ch"}, }, { Name: "Chuvash Wikibooks", Identifier: "chwikibooks", URL: "https://ch.wikibooks.org", Code: "wikibooks", InLanguage: struct{ Identifier string }{Identifier: "ch"}, }, } ``` -------------------------------- ### Define Wikimedia Project Configurations (Go) Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/metadata/README.md This Go code snippet defines configurations for various Wikimedia projects, including their names, identifiers, URLs, and language codes. It serves as a data structure for accessing different language editions of Wikimedia services. ```go package main import "fmt" func main() { projects := []struct { Name string `json:"name"` Identifier string `json:"identifier"` URL string `json:"url"` Code string `json:"code"` InLanguage struct { Identifier string `json:"identifier"` } `json:"in_language"` }{ { "name": "Wiktionary", "identifier": "aawiktionary", "url": "https://aa.wiktionary.org", "code": "wiktionary", "in_language": { "identifier": "aa" } }, { "name": "Wikibooks", "identifier": "aawikibooks", "url": "https://aa.wikibooks.org", "code": "wikibooks", "in_language": { "identifier": "aa" } }, { "name": "Wikipedia", "identifier": "astwiki", "url": "https://ast.wikipedia.org", "code": "wiki", "in_language": { "identifier": "ast" } }, { "name": "Wikcionariu", "identifier": "astwiktionary", "url": "https://ast.wiktionary.org", "code": "wiktionary", "in_language": { "identifier": "ast" } }, { "name": "Wikibooks", "identifier": "astwikibooks", "url": "https://ast.wikibooks.org", "code": "wikibooks", "in_language": { "identifier": "ast" } }, { "name": "Wikiquote", "identifier": "astwikiquote", "url": "https://ast.wikiquote.org", "code": "wikiquote", "in_language": { "identifier": "ast" } }, { "name": "Wikipedia", "identifier": "klwiki", "url": "https://kl.wikipedia.org", "code": "wiki", "in_language": { "identifier": "kl" } }, { "name": "Wiktionary", "identifier": "klwiktionary", "url": "https://kl.wiktionary.org", "code": "wiktionary", "in_language": { "identifier": "kl" } }, { "name": "維基百科", "identifier": "zh_yuewiki", "url": "https://zh-yue.wikipedia.org", "code": "wiki", "in_language": { "identifier": "zh-yue" } }, { "name": "ويكيبيديا", "identifier": "arwiki", "url": "https://ar.wikipedia.org", "code": "wiki", "in_language": { "identifier": "ar" } }, { "name": "ويكاموس", "identifier": "arwiktionary", "url": "https://ar.wiktionary.org", "code": "wiktionary", "in_language": { "identifier": "ar" } }, { "name": "ويكي الكتب", "identifier": "arwikibooks", "url": "https://ar.wikibooks.org", "code": "wikibooks", "in_language": { "identifier": "ar" } }, { "name": "ويكي الأخبار", "identifier": "arwikinews", "url": "https://ar.wikinews.org", "code": "wikinews", "in_language": { "identifier": "ar" } }, { "name": "ويكي الاقتباس", "identifier": "arwikiquote", "url": "https://ar.wikiquote.org", "code": "wikiquote", "in_language": { "identifier": "ar" } }, { "name": "ويكي مصدر", "identifier": "arwikisource", "url": "https://ar.wikisource.org", "code": "wikisource", "in_language": { "identifier": "ar" } }, { "name": "ويكي الجامعة", "identifier": "arwikiversity", "url": "https://ar.wikiversity.org", "code": "wikiversity", "in_language": { "identifier": "ar" } }, { "name": "विकिपिडिया", "identifier": "dtywiki", "url": "https://dty.wikipedia.org", "code": "wiki", "in_language": { "identifier": "dty" } }, { "name": "Wikipedia", "identifier": "guwwiki", "url": "https://guw.wikipedia.org", "code": "wiki", "in_language": { "identifier": "guw" } }, { "name": "Wiktionary", "identifier": "guwwiktionary", "url": "https://guw.wiktionary.org", "code": "wiktionary", "in_language": { "identifier": "guw" } }, { "name": "Wikilinlin", "identifier": "guwwikinews", "url": "https://guw.wikinews.org", "code": "wikinews", "in_language": { "identifier": "guw" } }, { "name": "Wikiquote", "identifier": "guwwikiquote", "url": "https://guw.wikiquote.org", "code": "wikiquote", "in_language": { "identifier": "guw" } }, { "name": "ڤیکیپئدیا", "identifier": "lrcwiki", "url": "https://lrc.wikipedia.org", "code": "wiki", "in_language": { "identifier": "lrc" } }, { "name": "ዊኪፔዲያ", "identifier": "tiwiki", "url": "https://ti.wikipedia.org", "code": "wiki", "in_language": { "identifier": "ti" } }, { "name": "ዊኪ-መዝገበ-ቃላት", "identifier": "tiwiktionary", "url": "https://ti.wiktionary.org", "code": "wiktionary", "in_language": { "identifier": "ti" } } } for _, p := range projects { fmt.Printf("Project: %s, Identifier: %s, URL: %s, Code: %s, Language: %s\n", p.Name, p.Identifier, p.URL, p.Code, p.InLanguage.Identifier) } } ``` -------------------------------- ### Download Snapshot with Parallel Requests Source: https://context7.com/wikimedia-enterprise/wme-sdk-go/llms.txt Demonstrates how to download a complete Wikipedia snapshot using concurrent range requests for optimized transfer speeds. ```APIDOC ## Download Snapshot with Parallel Requests ### Description Download a complete Wikipedia snapshot using concurrent range requests for faster transfers. ### Method POST ### Endpoint /api/v1/snapshot/{snapshot_id} ### Parameters #### Path Parameters - **snapshot_id** (string) - Required - The identifier for the snapshot to download (e.g., "enwiki_namespace_0"). #### Query Parameters None #### Request Body None ### Request Example (Code example provided in Go) ### Response #### Success Response (200) - **file** (io.Writer) - The downloaded snapshot file content. #### Response Example (Binary data stream for the snapshot file) ``` -------------------------------- ### Get Chunk Information Source: https://github.com/wikimedia-enterprise/wme-sdk-go/blob/main/example/snapshots/README.md Fetches metadata for a specific chunk of a snapshot. This allows you to get details about individual chunks, such as their version, modification date, and size, before downloading them. ```bash GET https://api.enterprise.wikimedia.com/v2/snapshots/hiwiki_namespace_0/chunks/1 ```